chunk es-toolkit
Splits an array into smaller arrays of a specified size.
Usage
chunk(arr, size)
Use chunk when you want to split a long array into multiple smaller arrays of the same size. If the array cannot be evenly divided, the last chunk will contain the remaining elements.
Splitting an empty array returns an empty array.
Parameters
arrT[]required
The array to split.
sizenumberrequired
The size of each chunk. Must be a positive integer.
Returns
A 2D array split into chunks of size size.
Throws
Throws an error if size is not a positive integer.
Try It
::: sandpack
:::
Source: es-toolkit
Re-exported verbatim from es-toolkit. Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.