Answers for "javascript array all but last element"

25

js take last item in array

const heroes = ["Batman", "Superman", "Hulk"];
const lastHero = heroes.pop(); // Returns last elment of the Array
// lastHero = "Hulk"
Posted by: Guest on March-16-2020
-1

javascript array last element

var lastEle = arr.slice(-1)[0];
// or
var lastEle = arr.slice(-1).pop();
Posted by: Guest on July-03-2020

Code answers related to "javascript array all but last element"

Code answers related to "Javascript"

Browse Popular Code Answers by Language