Function: chunk()
ts
function chunk<T>(array, size): T[][];Splits an array into groups with a fixed maximum size. 按固定最大长度将数组切分为多个分组。
Type Parameters
| Type Parameter | Description |
|---|---|
T | The type of array items / 数组元素类型 |
Parameters
| Parameter | Type | Description |
|---|---|---|
array | readonly T[] | The source array / 源数组 |
size | number | The size of each chunk / 每组大小 |
Returns
T[][]
The chunked result / 分组后的结果
Example
ts
chunk([1, 2, 3, 4, 5], 2)
// => [[1, 2], [3, 4], [5]]Since
1.2.0