fn
last
v0.0.3testedGets the last element of an array
Examples
ts
last([1, 2, 3, 4, 5]); // => 5ts
last([], 3); // => 3Signature
ts
export function last<Value>(arr: Value[], defaultValue?: Value){ ... }Type Parameters
ValueParameters
| Parameter | Type | Description |
|---|---|---|
arr | Value[] | The array to get the last element of |
defaultValue? | Value | undefined | The default value to return if the array is empty |
Returns
Value | undefinedThe last element of the array, or the default value if the array is empty