Function: first()
first<
ElementType>(iterable:IterableResolvable<ElementType>):ElementType|undefined
Consumes the first element of the iterable, returning it if it's found and undefined otherwise.
Type parameters
| Type parameter |
|---|
ElementType |
Parameters
| Parameter | Type | Description |
|---|---|---|
iterable | IterableResolvable<ElementType> | The iterator to return the first value of. |
Returns
ElementType | undefined
The first value of the iterator, or undefined if the iterator is empty.
Example
import { first } from '@sapphire/iterator-utilities';
const iterable = [1, 2, 3, 4, 5];
console.log(first(iterable));
// Output: 1
Remarks
This function consumes the first value of the iterator.
Source
projects/utilities/packages/iterator-utilities/src/lib/first.ts:22