Chunk
Chunk an array into smaller arrays of a specified size.
Category | Arrays |
Author | Pol Gubau |
Since | 1.0.0 |
Last Updated | 2025-03-15 |
Type | Sync |
Compatibility | Universal |
Example
Input
chunk([1, 2, 3, 4, 5], 2)
Output:
[[1, 2], [3, 4], [5]]
Return
An array of smaller arrays of the specified size.
Type: array[]
Props
Name | Type | Default | Required | Description |
---|---|---|---|---|
data | T[] | null | Yes | The array to be chunked. |
size | number | 10 | No | The size of each chunk. |
Notes
If the array length is not a multiple of size, the last chunk may be smaller.
Tags
- array
- chunk
- split