last es-toolkit
Returns the last element of an array.
Usage
last(arr)
Use last when you want to get the last element of an array. If the array is empty, it returns undefined. This is useful when accessing data at the end of an array.
Type handling is safe.
It works efficiently even with large arrays.
Parameters
arrreadonly T[]required
The array from which to get the last element.
Returns
The last element of the array. Returns undefined if the array is empty.
Source: es-toolkit
Re-exported verbatim from es-toolkit. Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.