How to extract the first 2 elements of an array in Typescript

1 Answer

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

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

console.log(first2); 

  
  
  
  
/*
run:
  
["javascript", "typescript"] 
  
*/

 



answered Jun 10, 2022 by avibootz

Related questions

...