javascript get last element of array

JavaScript
var colors = ["red","blue","green"];
var green = colors[colors.length - 1];//get last item in the arrayvar foods = ["kiwi","apple","banana"];
var banana = foods[foods.length - 1]; // Getting last elementvar name = ["jon","tem","kevin", "ramos"];
var lastNameInArray = name[name.length - 1];//  >> ramosvar array = [1,2,3,4,5,6];
var val = array[array.length - 1]; // 6var linkElement = document.getElementById("BackButton");
var loc_array = document.location.href.split('/');
var newT = document.createTextNode(unescape(capWords(loc_array[loc_array.length-2]))); 
linkElement.appendChild(newT);var animals = ['monkey', 'lion', 'don', 'frog', 'cow'];

var lastobject = animals[animals.length - 1];
	
	document.write('Last Element of array:-'+ lastobject );
	console.log(lastobject );console.log(2)console.log(2)var linkElement = document.getElementById("BackButton");
var loc_array = document.location.href.split('/');
var newT = document.createTextNode(unescape(capWords(loc_array[loc_array.length-2]))); 
linkElement.appendChild(newT);Yo an add that was searching this up, is where I found the chrome extension.
Source

Also in JavaScript: