xxxxxxxxxx
// haxe
var array:Array<T> = [object1, object2];
var lastItem = array[array.length];
xxxxxxxxxx
let arry = [2, 4, 6, 8, 10, 12, 14, 16];
let lastElement = arry[arry.length - 1];
console.log(lastElement);
xxxxxxxxxx
const myArray = [1, 2, 3, 4, 5];
// Using array indexing
const lastElement = myArray[myArray.length - 1];
console.log(lastElement); // This will print 5, which is the last element of the array
xxxxxxxxxx
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]
xxxxxxxxxx
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]
xxxxxxxxxx
let myArray = ["Hello!", "World!"]
let capacity = myArray.count
let lastElement = myArray[capacity-1]
print(lastElement)