chunk
Import from @varavel/vdl-plugin-sdk/utils/arrays.
Splits an array into smaller arrays of a specified length.
This function takes an input array and divides it into multiple smaller arrays, each of a specified length. If the input array cannot be evenly divided, the final sub-array will contain the remaining elements.
Type Parameters
| Type Parameter | Description |
|---|---|
T |
The type of elements in the array. |
Parameters
| Parameter | Type | Description |
|---|---|---|
arr |
readonly T[] |
The array to be chunked into smaller arrays. |
size |
number |
The size of each smaller array. Must be a positive integer. |
Returns
T[][]
A two-dimensional array where each sub-array has a maximum length of size.
Throws
Throws an error if size is not a positive integer.