get last item in array javascript

JavaScript
var colors = ["red","blue","green"];
var green = colors[colors.length - 1]; //get last item in the array
var colors = ["red","blue","green"];
var green = colors[colors.length - 1]; //get last item in the arrayvar colors = ["red","blue","green"];
var green = colors[colors.length - 1];//get last item in the arraylet array = [1,2,3,4,5];
let lastElement = array.pop();

// array -> [1,2,3,4];
// lastElement = 5;const nums = [1, 2, 3, 4, 5, 6, 7];
const lastOne = nums[nums.lenght - 1]; // last element of arrayif (loc_array[loc_array.length - 1] === 'index.html') {
   // do something
} else {
   // something else
}
Source

Also in JavaScript: