arrayItem
Returns the item at the specified index in the array, collection or enumerable object.
Signature
arrayItem<T>(input: T[] | undefined, index: number, default?: T): number
Parameters
Name | Type | Optional | Description |
---|---|---|---|
input | T[] | undefined | No | Specifies the array, collection or enumerable object. |
index | number | No | Specifies the zero based item index. |
default | T | Yes | Optional parameter which specifies the default value if the supplied index is invalid. |
Return value
Returns the item at the specified index.
Example
import { arrayItem } from "@tripetto/builder";
arrayItem<number>([1, 2, 3], 2); // Returns `3`
arrayItem<number>([1, 2, 3], 3); // Returns `undefined`
arrayItem<number>([1, 2, 3], 3, 0); // Returns `0`