how to refer to the last item in the array javascript 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: javascript last element of array
let arr = [1,2,3]
arr[arr.length - 1] //returns last element in an array