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.
Type Parameters
Section titled “Type Parameters”T extends DefinedValue
Parameters
Section titled “Parameters”iterable
Section titled “iterable”Iterable<T>
The iterable to read from.
Returns
Section titled “Returns”T | undefined
The last element, or undefined if there is none.