array last value code example
Example 1: last element of array javascript
var my_array = ;
var last_element = my_array[my_array.length - 1];
Example 2: find last element in array javascript
var heroes = ["Batman", "Superman", "Hulk"];
var lastHero = heroes.pop();
Example 3: get last item in array
let array = [1,2,3,4,5]
let sliced = array.slice(-1)[0]
let popped = array.slice(-1).pop()
let lengthed = array[array.length - 1]
Example 4: get last element in array in js
var array = ['red','green','yellow']
console.log(array[array.length-1])
Example 5: find last item in an array JS
if (loc_array[loc_array.length - 1] === 'index.html') {
} else {
}