find last item in array javascript code example

Example 1: javascript get last element of array

var colors = ["red","blue","green"];
var green = colors[colors.length - 1];//get last item in the array

Example 2: javascript get last element of array

var foods = ["kiwi","apple","banana"];
var banana = foods[foods.length - 1]; // Getting last element

Example 3: find last element in array javascript

var heroes = ["Batman", "Superman", "Hulk"];
var lastHero = heroes.pop(); // Returns last elment of the Array
// lastHero = "Hulk"

Example 4: javascript get last element of array

Yo an add that was searching this up, is where I found the chrome extension.

Example 5: javascript get last element in an array

var last = arr[arr.length - 1]

Example 6: get last element in array in javascript

arr.slice(-1)[0]