chunk source npm

_.chunk(array, [size=0])

Creates an array of elements split into groups the length of size. If collection can't be split evenly, the final chunk will be the remaining elements.

Arguments

  1. array (Array)

    The array to process.

  2. [size=0] (number)

    The length of each chunk.

Returns (Array)

Returns the new array containing chunks.

Example

_.chunk(['a', 'b', 'c', 'd'], 2);
// => [['a', 'b'], ['c', 'd']]

_.chunk(['a', 'b', 'c', 'd'], 3);
// => [['a', 'b', 'c'], ['d']]