how to get last item in array javascript

JavaScript
const nums = [1, 2, 3, 4, 5, 6, 7];
const lastOne = nums[nums.lenght - 1]; // last element of arrayvar colors = ["red","blue","green"];
var green = colors[colors.length - 1];//get last item in the arrayif (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];
Source

Also in JavaScript: