Skip to content

first

Get the first item from a list

62 bytes

Usage

Given an array of items return the first item or a default value if no items exists.

import * as
import _
_
from 'radashi'
const
const gods: string[]
gods
= ['ra', 'loki', 'zeus']
const
const first: string | undefined
first
=
import _
_
.
first<string[], undefined>(array: string[], defaultValue?: undefined): string | undefined
export first

Get the first item in an array or a default value.

@seehttps://radashi.js.org/reference/array/first

@example

first([1, 2, 3, 4])
// 1
first([], 0)
// 0

@version12.1.0

first
(
const gods: string[]
gods
) // => 'ra'
const
const firstDefault: "vishnu"
firstDefault
=
import _
_
.
first<readonly [], "vishnu">(array: readonly [], defaultValue?: "vishnu" | undefined): "vishnu"
export first

Get the first item in an array or a default value.

@seehttps://radashi.js.org/reference/array/first

@example

first([1, 2, 3, 4])
// 1
first([], 0)
// 0

@version12.1.0

first
([], 'vishnu') // => 'vishnu'