Function: at()
at<
ElementType
>(iterable
:IterableResolvable
<ElementType
>,index
:number
):ElementType
|undefined
Advances the iterable to the n
th element and returns it. If the iterable is exhausted before reaching the n
th element, it returns undefined
.
Type Parameters
Type Parameter |
---|
ElementType |
Parameters
Parameter | Type | Description |
---|---|---|
iterable | IterableResolvable <ElementType > | An iterator to return an element from. |
index | number | The index of the element to retrieve. |
Returns
ElementType
| undefined
The element at the specified index, or undefined
if the index is out of range.
Example
import { at } from '@sapphire/iterator-utilities';
const iterable = [1, 2, 3, 4, 5];
console.log(at(iterable, 2));
// Output: 3
Remarks
This function consumes the input iterator up to the specified index.
Defined in
projects/utilities/packages/iterator-utilities/src/lib/at.ts:27