Answers for "how to choose the last item in an array"

26

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
0

how to find last element of an array

let arry = [2, 4, 6, 8, 10, 12, 14, 16];
let lastElement = arry[arry.length - 1];

console.log(lastElement);
Posted by: Guest on December-20-2021

Code answers related to "how to choose the last item in an array"

Code answers related to "Javascript"

Browse Popular Code Answers by Language