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
Name | Type | Optional | Description |
---|---|---|---|
array | TList<T> | No | Specifies the array, collection or enumerable object. |
default | T | Yes | Optional 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`