Using Array.slice for Non-destructive Array Operations in Javascript


Create a shallow copy of a portion of an array without modifying the original array.

Source Code

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