head

array

Gets the first element of array.

Signature

head<T>(array: T[]): T | undefined

Parameters

NameTypeDescription
arrayT[]The array to query

Returns

T | undefined - Returns the first element of array

Examples

Basic usage

import { head } from 'dashlite'

const result = head([1, 2, 3])
console.log(result)

Output:

1

Empty array

import { head } from 'dashlite'

const result = head([])
console.log(result)

Output:

undefined

Available since version 1.0.0