🎯 Returns the first element of the array.

Syntax

TypeScript
import { first } from '@opentf/std';

first<T>(arr: T[] = []): T | undefined

Parameters

  • arr: The source array.

Returns

The first element, or undefined if the array is empty.

Examples

TypeScript
first([1, 2, 3]) //=> 1

first(['a', 'b', 'c']) //=> 'a'

first([]) //=> undefined

first() //=> undefined
Last updated on
Edit this page