Function: first()
first<
ElementType>(iterable:IterableResolvable<ElementType>):undefined|ElementType
Defined in: projects/utilities/packages/iterator-utilities/src/lib/first.ts:22
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
undefined | ElementType
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.