how to get last item in array javascript
snippet in javascript

javascript get last element of array

user1884

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

js take last item in array

user6074

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

Javascript get last item in array

user6592

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

javascript get last element of array

user5835

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

how to get last item in array javascript

user4540

let nums = [1,2,3,4,5];
let lastOne = nums.pop();
// -> lastOne = 5
// -> nums = [1,2,3,4];

last element of array javascript

user7481

if (loc_array[loc_array.length - 1] === 'index.html') {
   // do something
} else {
   // something else
}