How to add 2 elements to an array start at specific index in Node.js

1 Answer

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

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

*/

 



answered Jul 5, 2022 by avibootz
...