R
fn

last

v0.0.3tested

Gets the last element of an array

Examples

ts
last([1, 2, 3, 4, 5]); // => 5
ts
last([], 3); // => 3

Signature

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

Type Parameters

Value

Parameters

ParameterTypeDescription
arrValue[]The array to get the last element of
defaultValue?Value | undefinedThe 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