Skip to content

Instantly share code, notes, and snippets.

@NathanKleekamp
Last active September 1, 2018 11:53
Show Gist options
  • Save NathanKleekamp/acbbed7fc93c91c04a520c78ed484fee to your computer and use it in GitHub Desktop.
Save NathanKleekamp/acbbed7fc93c91c04a520c78ed484fee to your computer and use it in GitHub Desktop.
A JS utility to get all but the first items in an array
// const rest = array => array.slice(1, array.length);
const rest = ([first, ...rest]) => rest
const testArray = [1, 2, 3, 4, 5];
rest(testArray) // [2, 3, 4, 5];
rest([]).length === 0; // true
Array.isArray(rest([])); // true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment