Skip to main content

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

NameTypeOptionalDescription
inputT[] | undefinedNoSpecifies the array, collection or enumerable object.
indexnumberNoSpecifies the zero based item index.
defaultTYesOptional 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";

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`