chunk
Modified on Sun, 13 Aug 2023
Description
Create an array of elements split into groups the length of size.
Syntax
chunk(array, size)
Parameters
Input Parameter | Type | Description |
---|---|---|
array | Array | The array to process |
size | number | The length of each chunk |
Return value
Type |
---|
Array<Array<any>> |
Example | Result | Description |
---|---|---|
chunk(['a', 'b', 'c', 'd'], 2) | [['a', 'b'], ['c', 'd']] | Returns the new array of chunks with size 2 |
chunk(['a', 'b', 'c', 'd'], 3) | [['a', 'b', 'c'], ['d']] | Returns the new array of chunks with size 3. |
To view all the List functions, click here.
See Also
Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article