Skip to content

Array.first method

Array › first

Official

Returns the first element of the array.

Signature:

first(): T | undefined

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

Example:

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