Q:

what's the last element of an array

 return array[array.length - 1];
4
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)
1
var arr = [1,2,3]
var lastelementofarr = [arr.length-1] //I think it will return the last element in the array
3
int[] array = {1,2,3};
System.out.println(array[array.length - 1]);
1

New to Communities?

Join the community