xdash API Reference / firstOrDefault
Function: firstOrDefault()
firstOrDefault<
T
,D
>(arr
,defaultValue
):T
|D
Defined in: src/array.ts:250
Returns the first element of an array, or a default value if the array is empty.
Type Parameters
T
T
D
D
Parameters
arr
T
[]
array to get the first element from
defaultValue
D
default value
Returns
T
| D
the first element of the array, or the default value if the array is empty
Example
ts
firstOrDefault([1, 2, 3], 0) // returns 1
firstOrDefault([], 0) // returns 0