Function: forEach()
forEach<
ElementType
>(iterable
:IterableResolvable
<ElementType
>,callbackFn
: (element
:ElementType
,index
:number
) =>void
):void
Executes a provided function once for each iterable element.
Type Parameters
Type Parameter |
---|
ElementType |
Parameters
Parameter | Type | Description |
---|---|---|
iterable | IterableResolvable <ElementType > | An iterator to iterate over. |
callbackFn | (element : ElementType , index : number ) => void | A function to execute for each element produced by the iterator. Its return value is discarded. |
Returns
void
Example
import { forEach } from '@sapphire/iterator-utilities';
const iterable = [1, 2, 3, 4, 5];
forEach(iterable, (value) => console.log(value));
// Output: 1, 2, 3, 4, 5
Remarks
This function consumes the entire iterator.
Defined in
projects/utilities/packages/iterator-utilities/src/lib/forEach.ts:24