return array[array.length - 1];
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]
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]
var Cars = ["Volvo", "Mazda", "Lamborghini", "Maserati"]; //We can get the total number of elements like this. var hmCars = Cars.pop(); //hmCars is now Maserati console.log(hmCars)
var arr = [1,2,3] var lastelementofarr = [arr.length-1] //I think it will return the last element in the array
const myArray = [1, 2, 3] console.log(myArray.item(-1)) //=> 3
//the last one
int [] y={1,2,3,4,5}; int c=(n.length-1);