0
Q:

how to select last element in a array

 return array[array.length - 1];
4
let array = [1,2,3,4,5]

let sliced = array.slice(-1)[0]

//OR

let popped = array.slice(-1).pop()

//OR

let lengthed = array[array.length - 1]
3
let array = [0, 1, 2, 3, 4, 5, 6, 7] 
console.log(array.slice(-1));
>>>[7]
console.log(array.slice(-2));
>>>[6, 7]
console.log(array.slice(-3));
>>>[5, 6, 7]
1
if (loc_array[loc_array.length - 1] === 'index.html') {
   // do something
} else {
   // something else karunakar
}
0
int[] karunakar={1,2,3};
System.out.println(karunakar[karunakar.length-1]);
0
let myArray = ["Hello!", "World!"]
let capacity = myArray.count
let lastElement = myArray[capacity-1]
print(lastElement)
0
int [] y={1,2,3,4,5};
int c=(n.length-1);
-1

New to Communities?

Join the community