Arrays

https://www.geeksforgeeks.org/get-the-first-and-last-item-in-an-array-using-javascript/

by Annie Lagang

JavaScript

let s = [1, 2, 3, 4, 5];
function Gfg() {
 
    // Storing the first item in a variable
    let f = s.slice(0, 1);
 
    // Storing the last item
    let l = s.slice(-1);
    
    let middle = s.slice(1, -1); 
 
 
    // Printing output to screen
    console.log("first element is " + f);
    console.log("Last element is " + l);
    console.log("Rest are " + middle);
}
Gfg(); // Calling the function