Function: chunk()
chunk<
ElementType>(iterable:IterableResolvable<ElementType>,size:number):IterableIterator<ElementType[]>
Defined in: projects/utilities/packages/iterator-utilities/src/lib/chunk.ts:21
Chunks the iterable into arrays of at most size elements.
Type Parameters
| Type Parameter |
|---|
ElementType |
Parameters
| Parameter | Type | Description |
|---|---|---|
iterable | IterableResolvable<ElementType> | The iterator whose elements to chunk. |
size | number | The maximum size of each chunk. |
Returns
IterableIterator<ElementType[]>
Example
import { chunk } from '@sapphire/iterator-utilities';
const iterable = [1, 2, 3, 4, 5];
console.log([...chunk(iterable, 2)]);
// Output: [[1, 2], [3, 4], [5]]