how to get last index in array javascript code example
Example 1: javascript get last element of array
var foods = ["kiwi","apple","banana"];
var banana = foods[foods.length - 1];
Example 2: javascript get last element of array
var colors = ["red","blue","green"];
var green = colors[colors.length - 1];
Example 3: javascipt get last element of array
const arr = [1,2,3] ;
console.log(arr[arr.length - 1]);
Example 4: js last index of
const str = "Users/Edit/12345";
let idx = str.lastIndexOf("/");
idx = str.lastIndexOf("x");
idx = str.lastIndexOf("Edit")
idx = str.lastIndexOf("edit")
idx = str.lastIndexOf("s");
idx = str.lastIndexOf("s", 3);
Example 5: get last element in array in js
var array = ['red','green','yellow']
console.log(array[array.length-1])
Example 6: javascript code for find the last element in array
if (loc_array[loc_array.length - 1] === 'index.html') {
} else {
}