Skip to main content

firstArrayItem

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

Signature

firstArrayItem<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 first item.

Return value

Returns the first item or undefined if there is none.

Example

import { firstArrayItem } from "@tripetto/runner";

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