Skip to content

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.

any[]

a sample

number

size of each output array. must be a positive integer

any[][]

a chunked array

if chunk size is less than 1 or not an integer

chunk([1, 2, 3, 4, 5, 6], 2);
// => [[1, 2], [3, 4], [5, 6]]