get last item in array javascript
snippet in javascript

javascript get last element of array

user9118

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

js take last item in array

user5153

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

Javascript get last item in array

user6821

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

javascript get last element of array

user9533

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

get last item in array javascript

user3020

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

get last item in array javascript

user7509

var colors = ["black", "white", "red", "yellow"];
var yellow = colors[colors.length - 1];