Skip to content

Instantly share code, notes, and snippets.

@kjk
Last active July 19, 2020 11:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kjk/036ec15721848ba78806afd6f461c6e5 to your computer and use it in GitHub Desktop.
Save kjk/036ec15721848ba78806afd6f461c6e5 to your computer and use it in GitHub Desktop.
const arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
let newArr = arr.slice(0, 2);
console.log("slice(0,2) :", newArr)
newArr = arr.slice(8);
console.log("slice(8) :", newArr)
newArr = arr.slice(5, -1);
console.log("slice(5, -1):", newArr)
newArr = arr.slice(6, -2);
console.log("slice(6, -2):", newArr)
newArr = arr.slice(3, 3)
console.log("slice(3, 3) :", newArr)
newArr = arr.slice(4, 1)
console.log("slice(4, 1) :", newArr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment