var arr = [ 1, 2, 3, 4 ]; var first = arr[0]; var rest = arr.slice(1); // first: 1 // rest: [ 2, 3, 4 ]
Recursion in JavaScript with ES6, destructuring and rest/spread
Hugo Di Francesco
2309

Or you could have used:

var first= arr.pop()

So that first would have the first value and arr would be the rest equivalent. It is useful if the previous version of arr can be discarded.

Show your support

Clapping shows how much you appreciated Claudio Brogliato’s story.