How to add element to array at specific index in JavaScript

1 Answer

0 votes
const arr = ['javascript', 'php', 'python', 'c', 'c#'];
 
const index = 1;

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

 



answered Jul 4, 2022 by avibootz

Related questions

3 answers 263 views
1 answer 161 views
1 answer 144 views
1 answer 178 views
1 answer 171 views
...