UNPKG

diginext-utils

Version:
21 lines 523 B
/** * 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' * ``` */ export function last(array) { if (!Array.isArray(array) || array.length === 0) { return undefined; } return array[array.length - 1]; } //# sourceMappingURL=last.js.map