take last index of array code example
Example 1: js take last item in array
const heroes = ["Batman", "Superman", "Hulk"];
const lastHero = heroes.pop(); // Returns last elment of the Array
// lastHero = "Hulk"
Example 2: how to get the last eleemnt of an array
var Cars = ["Volvo", "Mazda", "Lamborghini", "Maserati"];
//We can get the total number of elements like this.
var hmCars = Cars.pop();
//hmCars is now Maserati
console.log(hmCars)