javascript get last element of array
var foods = ["kiwi","apple","banana"];
var banana = foods[foods.length - 1]; // Getting last element
javascript get last element of array
var foods = ["kiwi","apple","banana"];
var banana = foods[foods.length - 1]; // Getting last element
js take last item in array
const heroes = ["Batman", "Superman", "Hulk"];
const lastHero = heroes.pop(); // Returns last elment of the Array
// lastHero = "Hulk"
find last element in array javascript
var heroes = ["Batman", "Superman", "Hulk"];
var lastHero = heroes.pop(); // Returns last elment of the Array
// lastHero = "Hulk"
get last element in array in javascript
arr.slice(-1)[0]
lastindexof
var numbers = [2, 5, 9, 2];
numbers.lastIndexOf(2); // 3
numbers.lastIndexOf(7); // -1
numbers.lastIndexOf(2, 3); // 3
numbers.lastIndexOf(2, 2); // 0
numbers.lastIndexOf(2, -2); // 0
numbers.lastIndexOf(2, -1); // 3
get last item in array js
if (loc_array[loc_array.length - 1] === 'index.html') {
// do something
} else {
// something else
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us