diginext-utils
Version:
README.md
21 lines • 516 B
JavaScript
/**
* 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'
* ```
*/
export function first(array) {
if (!Array.isArray(array) || array.length === 0) {
return undefined;
}
return array[0];
}
//# sourceMappingURL=first.js.map