find last item in an array JS

JavaScript
if (loc_array[loc_array.length - 1] === 'index.html') {
   // do something
} else {
   // something else
}let nums = [1,2,3,4,5];
let lastOne = nums.pop();
// -> lastOne = 5
// -> nums = [1,2,3,4];var colors = ["red","blue","green"];
var green = colors[colors.length - 1];//get last item in the arrayconst heroes = ["Batman", "Superman", "Hulk"];
const lastHero = heroes.pop(); // Returns last elment of the Array
// lastHero = "Hulk"
Source

Also in JavaScript: