R
fn

first

v0.0.3tested

Returns the first element of an array

Examples

ts
first([1, 2, 3]); // => 1
ts
first([]); // => undefined

Signature

ts
export function first<Value>(arr: Value[], defaultValue?: Value){ ... }

Type Parameters

Value

Parameters

ParameterTypeDescription
arrValue[]The array to get the first element from
defaultValue?Value | undefinedThe default value to return if the array is empty

Returns

Value | undefinedThe first element of the array, or the default value if the array is empty