chunk
chunk(
x,chunkSize):any[][]
Defined in: src/chunk.js:18
Split an array into chunks of a specified size. This function has the same behavior as PHP’s array_chunk function, and thus will insert smaller-sized chunks at the end if the input size is not divisible by the chunk size.
x is expected to be an array, and chunkSize a number.
The x array can contain any kind of data.
Parameters
Section titled “Parameters”any[]
a sample
chunkSize
Section titled “chunkSize”number
size of each output array. must be a positive integer
Returns
Section titled “Returns”any[][]
a chunked array
Throws
Section titled “Throws”if chunk size is less than 1 or not an integer
Example
Section titled “Example”chunk([1, 2, 3, 4, 5, 6], 2);// => [[1, 2], [3, 4], [5, 6]]