How to remove N elements from specific index in array with JavaScript

1 Answer

0 votes
let arr = ['javascript', 'c++', 'php', 'c', 'swift', 'c#'];
 
let index = 1;
let N = 3;

let removedItems = arr.splice(index, N);

console.log(removedItems);

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

 



answered Nov 29, 2020 by avibootz
...