var heroes = ["Batman", "Superman", "Hulk"]; var lastHero = heroes.pop(); // Returns last elment of the Array // lastHero = "Hulk"
var colors = ["red","blue","green"]; var green = colors[colors.length - 1]; //get last item in the array
arr.slice(-1)[0]
var colors = ["black", "white", "red", "yellow"]; var yellow = colors[colors.length - 1];
const numArray = [1,2,3,4,5]; const lastNumber = numArray.reverse()[0];
if (loc_array[loc_array.length - 1] === 'index.html') { // do something } else { // something else }
var a = loc_array.slice(-1)[0]
get last item of array javascript
var my_array = /* some array here */; var last_element = my_array[my_array.length - 1];