How to extract the first 2 elements of an array in Node.js

1 Answer

0 votes
const arr = ['javascript', 'node.js', 'typescript', 'c++', 'python'];

const first2 = arr.slice(0, 2);

console.log(first2); 

  
  
  
  
/*
run:
  
[ 'javascript', 'node.js' ]
  
*/

 



answered Jun 10, 2022 by avibootz
...