How to add element to array at specific index in Node.js

1 Answer

0 votes
const arr = ['node.js', 'php', 'python', 'c', 'c++', 'c#'];
 
const index = 2;

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

 



answered Jul 4, 2022 by avibootz

Related questions

3 answers 217 views
1 answer 164 views
1 answer 156 views
...