javascript array last element

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

// array -> [1,2,3,4];
// lastElement = 5;var lastEle = arr.slice(-1)[0];
// or
var lastEle = arr.slice(-1).pop();arr.slice(-1)[0] if (loc_array[loc_array.length - 1] === 'index.html') {
   // do something
} else {
   // something else
}var my_array = /* some array here */;
var last_element = my_array[my_array.length - 1];
Source

Also in JavaScript: