1. Home
  2. Javascript
  3. Last n items
#javascript#array

Select last n items from array

// Number of items to select
numberOfItems = 100;
// Create a new array with last N items
let selectedArray = originalArray.slice( Math.max( originalArray.length - numberOfItems, 1 ) );
copy
Full Javascript cheatsheet
Sitemap Git repository