nire0510
7/16/2017 - 7:26 AM

Splice vs. Slice

Splice vs. Slice

let a = [1, 2, 3, 4, 5, 6];
let b = [1, 2, 3, 4, 5, 6];

console.log('-- SLICE --');
console.log('- Returns values which were removed');
console.log('- Does not change the original array');
console.log(a.slice(0, 2));
console.log(a);

console.log();

console.log('-- SPLICE --');
console.log('- Returns values which were removed');
console.log('- Changes the original array');
console.log(b.splice(0, 2));
console.log(b);