How to replace element in an array in specific index with JavaScript

1 Answer

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

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

 



answered Jul 4, 2022 by avibootz
...