dependabit / utils/src / chunk
Function: chunk()
ts
function chunk<T>(arr, size): T[][];Defined in: packages/utils/src/array.ts:76
Splits an array into consecutive chunks of the given size.
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type | Description |
|---|---|---|
arr | T[] | The array to chunk. |
size | number | Maximum number of elements per chunk. |
Returns
T[][]
Array of chunks; the last chunk may be smaller than size.
Example
ts
chunk([1, 2, 3, 4, 5], 2); // [[1, 2], [3, 4], [5]]