fn
first
v0.0.3testedReturns the first element of an array
Examples
ts
first([1, 2, 3]); // => 1ts
first([]); // => undefinedSignature
ts
export function first<Value>(arr: Value[], defaultValue?: Value){ ... }Type Parameters
ValueParameters
| Parameter | Type | Description |
|---|---|---|
arr | Value[] | The array to get the first element from |
defaultValue? | Value | undefined | The 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