Skip to content

Array.last method

Array › last

Official

Returns the last element of the array.

Signature:

last(): T | undefined

Returns: T | undefinedThe last element of the array, or undefined if the array is empty.

Example:

console.log([1, 2, 3].last()); // 3
console.log([].last()); // undefined