last

Obtiene el último elemento de un array de forma segura.

#array #utility
export const last = <T>(arr: readonly T[]): T | undefined =>
arr[arr.length - 1];
// Usage
last([1, 2, 3]); // 3
last([]); // undefined

Comparte este snippet

Comentarios