Skip to content

Instantly share code, notes, and snippets.

@bobdobbalina
Created July 21, 2020 14:04
Show Gist options
  • Select an option

  • Save bobdobbalina/3204f2e9255c637f81dd646999a741a8 to your computer and use it in GitHub Desktop.

Select an option

Save bobdobbalina/3204f2e9255c637f81dd646999a741a8 to your computer and use it in GitHub Desktop.
Javascript: Get Last Items in an Array
let array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
console.log(array.slice(-1)); // Result: [9]
console.log(array.slice(-2)); // Result: [8, 9]
console.log(array.slice(-3)); // Result: [7, 8, 9]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment