How to replace 2 elements in an array start from specific index with Node.js

1 Answer

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

const index = 1;
 
arr.splice(index, 2, "c++", "java");
  
console.log(arr); 
  
  
  
  
/*
run:
  
[ 'node.js', 'c++', 'java', 'c', 'go', 'c#' ]
  
*/

 



answered Jul 5, 2022 by avibootz
...