source: node_modules/es-toolkit/dist/compat/array/head.d.mts@ ba17441

Last change on this file since ba17441 was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 1.1 KB
Line 
1/**
2 * Returns the first element of an array or `undefined` if the array is empty.
3 *
4 * @template T - The type of elements in the array.
5 * @param {readonly [T, ...unknown[]]} array - A non-empty tuple with at least one element.
6 * @returns {T} The first element of the array.
7 *
8 * @example
9 * const arr = [1, 2, 3] as const;
10 * const first = head(arr);
11 * // first will be 1
12 */
13declare function head<T>(array: readonly [T, ...unknown[]]): T;
14/**
15 * Returns the first element of an array or `undefined` if the array is empty.
16 *
17 * @template T - The type of elements in the array.
18 * @param {ArrayLike<T> | null | undefined} array - The array from which to get the first element.
19 * @returns {T | undefined} The first element of the array, or `undefined` if the array is empty/null/undefined.
20 *
21 * @example
22 * const arr = [1, 2, 3];
23 * const first = head(arr);
24 * // first will be 1
25 *
26 * const emptyArr: number[] = [];
27 * const noElement = head(emptyArr);
28 * // noElement will be undefined
29 */
30declare function head<T>(array: ArrayLike<T> | null | undefined): T | undefined;
31
32export { head };
Note: See TracBrowser for help on using the repository browser.