Skip to content

Instantly share code, notes, and snippets.

@rjmacarthy
Created April 21, 2016 15:06
Show Gist options
  • Save rjmacarthy/e426125e5f91fc5d7864eff03d632047 to your computer and use it in GitHub Desktop.
Save rjmacarthy/e426125e5f91fc5d7864eff03d632047 to your computer and use it in GitHub Desktop.
Get a chunk of array from the end.
var arr = [ -3, 1, 2, -2, 5, 6 ]
var chunkAmount = 3;
var chunk = arr.splice(arr.length-chunkAmount,arr.length);
console.log(chunk) // [-2, 5, 6 ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment