find last element in array javascript

JavaScript
var heroes = ["Batman", "Superman", "Hulk"];
var lastHero = heroes.pop(); // Returns last elment of the Array
// lastHero = "Hulk"let nums = [1,2,3,4,5];
let lastOne = nums.pop();
// -> lastOne = 5
// -> nums = [1,2,3,4];if (loc_array[loc_array.length - 1] === 'index.html') {
   // do something
} else {
   // something else
}let arr = [1,2,3]
arr[arr.length - 1] //returns last element in an arrayconst heroes = ["Batman", "Superman", "Hulk"];
const lastHero = heroes.pop(); // Returns last elment of the Array
// lastHero = "Hulk"let arr = ['a', 'b', 'c']
arr.slice(-1)[0] // returns last element in an array
arr.pop()
Source

Also in JavaScript: