Array.chunk
Array.chunk
Function
Split the array into a two-dimensional array according to the specified size.
Syntax
array.chunk(size)
Parameters
| Parameters | Type | Required | Default value | Description |
|---|---|---|---|---|
| size | Number | No | 1 | The number of elements in each group. |
Return value
| Type | Description |
|---|---|
| Array | Split two-dimensional array. |
Code Example
result = [1, 2, 3, 4, 5].chunk(2) // Output: [[1,2],[3,4],[5]] print result
Notes
- Returns an empty array when size is less than or equal to 0.