How to add element to array at specific index in TypeScript

1 Answer

0 votes
const arr = ['typescript', 'php', 'python', 'c', 'c++', 'php'];
 
const index = 3;

arr.splice(index, 0, "c#");
 
console.log(arr); 
   
   
     
       
       
/*
run:
       
["typescript", "php", "python", "c#", "c", "c++", "php"] 
       
*/

 



answered Jul 4, 2022 by avibootz
...