UNPKG

diginext-utils

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