Skip to content

last

last<T>(iterable): T | undefined

Defined in: packages/core/src/iterable/last.ts:15

Returns the last element, or undefined when the iterable is empty.

T cannot itself include undefined, so the absent case is never ambiguous. Use compact first when the source may carry nullish elements.

Time complexity: O(1) for an array, which is indexed directly; O(n) for any other iterable, which has to be drained to reach its end.

T extends DefinedValue

Iterable<T>

The iterable to read from.

T | undefined

The last element, or undefined if there is none.