diginext-utils
Version:
README.md
24 lines • 614 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.last = last;
/**
* Returns the last element of an array.
*
* @template T - The type of elements in the array
* @param array - The array to get the last element from
* @returns The last element, or undefined if array is empty
*
* @example
* ```ts
* last([1, 2, 3]); // 3
* last([]); // undefined
* last(['a', 'b', 'c']); // 'c'
* ```
*/
function last(array) {
if (!Array.isArray(array) || array.length === 0) {
return undefined;
}
return array[array.length - 1];
}
//# sourceMappingURL=last.js.map