Splits an array into consecutive chunks of at most size elements.
size
The final chunk may be smaller when the array length is not evenly divisible.
Array to split into consecutive segments.
Maximum number of elements per chunk; the final chunk may contain fewer.
Consecutive slices of arr, each up to size elements long. Returns [] when arr is empty.
arr
[]
chunk([1, 2, 3, 4], 2); // [[1, 2], [3, 4]]chunk([1, 2, 3, 4, 5], 2); // [[1, 2], [3, 4], [5]]chunk([1, 2, 3], 10); // [[1, 2, 3]] (size larger than array)chunk([], 2); // [] Copy
chunk([1, 2, 3, 4], 2); // [[1, 2], [3, 4]]chunk([1, 2, 3, 4, 5], 2); // [[1, 2], [3, 4], [5]]chunk([1, 2, 3], 10); // [[1, 2, 3]] (size larger than array)chunk([], 2); // []
Splits an array into consecutive chunks of at most
sizeelements.The final chunk may be smaller when the array length is not evenly divisible.