Removing Array Elements Without Mutating with slice in Javascript


Use slice() to remove elements without changing the original array.

Source Code

let numbers = [1, 2, 3, 4, 5];
let withoutThree = numbers.slice(0, 2).concat(numbers.slice(3));
console.log(withoutThree); // [1, 2, 4, 5]
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments