ES6 Spread operator + .shift() solution
Using myArray.shift() you can get the 1st element of the array, but .shift() will modify the original array, so to avoid this, first you can create a copy of the array with [...myArray] and then apply the .shift() to this copy:
var…
Top comments (2)
What about keeping it simple as suggested in the accepted answer?
stackoverflow.com/a/4090513
Your right on your statement ..but I think when I handle
Statelike in react/vue. It's handy & depend on situation....