Skip to content

Instantly share code, notes, and snippets.

@ancyrweb
Last active January 11, 2022 14:39
Show Gist options
  • Save ancyrweb/3b7168b5c13e7a51bf270973531d0017 to your computer and use it in GitHub Desktop.
Save ancyrweb/3b7168b5c13e7a51bf270973531d0017 to your computer and use it in GitHub Desktop.
const elements = [1, 2, 3, 4, 5];
// remove last element
const lastElementRemoved = elements.slice(0, 4); // [1, 2, 3, 4]
// remove first element
const firstElementRemoved = elements.slice(1); // [2, 3, 4, 5]
// remove first and last element (chaining)
const firstAndLastElementRemoved = elements.slice(0, 4).slice(1) // [2, 3, 4]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment