get last element of array javascript slice code example
Example 1: js take last item in array
const heroes = ["Batman", "Superman", "Hulk"];
const lastHero = heroes.pop();
Example 2: how to get the last eleemnt of an array
var Cars = ["Volvo", "Mazda", "Lamborghini", "Maserati"];
var hmCars = Cars.pop();
console.log(hmCars)
Example 3: javascipt get last element of array
const arr = [1,2,3] ;
console.log(arr[arr.length - 1]);
Example 4: how to get the last element of an array
let arr = ["s","fg","d"]
print(arr[arr.length-1])