javascript get the last element of an array

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 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 arr = ['a', 'b', 'c']
arr.slice(-1)[0] // returns last element in an array
arr.pop()//the last one 
Source

Also in JavaScript: