Getting First and Last Items in Array (and splitting all the rest)

PHOTO EMBED

Fri Apr 24 2020 11:44:23 GMT+0000 (Coordinated Universal Time)

Saved by @Bornconfused #css #css #items #array

 const arr = ["This", "Little", "Piggy"];
const first = arr.slice(0, 1);
const the_rest = arr.slice(1);console.log(first); // ["This"]
console.log(the_rest); // ["Little", "Piggy"]                               
                                
content_copyCOPY

The .slice() array method had my back here nicely. It won’t mess with the original array.

https://css-tricks.com/snippets/javascript/getting-first-and-last-items-in-array-and-splitting-all-the-rest/