Creates an array of elements split into groups the length of size. If array can't be split evenly, the final chunk will be the remaining elements.
size
array
5.18.0
chunk(['a', 'b', 'c', 'd'], 2)// => [['a', 'b'], ['c', 'd']]chunk(['a', 'b', 'c', 'd'], 3)// => [['a', 'b', 'c'], ['d']] Copy
chunk(['a', 'b', 'c', 'd'], 2)// => [['a', 'b'], ['c', 'd']]chunk(['a', 'b', 'c', 'd'], 3)// => [['a', 'b', 'c'], ['d']]
The array to process.
The length of each chunk, default is 1
Returns the new array of chunks.
Creates an array of elements split into groups the length of
size
. Ifarray
can't be split evenly, the final chunk will be the remaining elements.Since
5.18.0
Example