Skip to content

Instantly share code, notes, and snippets.

@nire0510
Last active September 19, 2017 15:24
Show Gist options
  • Save nire0510/1383f1424512a4fde37d0ad7a261d5e6 to your computer and use it in GitHub Desktop.
Save nire0510/1383f1424512a4fde37d0ad7a261d5e6 to your computer and use it in GitHub Desktop.
[Splice vs. Slice] #javascript
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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment