Skip to main content

lastArrayItem

Returns the last item in the array, collection or enumerable object.

Signature

lastArrayItem<T>(array: TList<T> | undefined, index: number, default?: T): T | undefined

Parameters

NameTypeOptionalDescription
arrayTList<T>NoSpecifies the array, collection or enumerable object.
defaultTYesOptional parameter which specifies the default value if there is no last item.

Return value

Returns the last item or undefined if there is none.

Example

import { lastArrayItem } from "@tripetto/builder";

lastArrayItem<number>([1, 2, 3]); // Returns `3`