DEV Community

Lam Hoang
Lam Hoang

Posted on

Creates an array of elements split into groups the length of size.

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.

Arguments

  • array (Array): The array to process.
  • [size=1] (number): The length of each chunk

Returns

  • (Array): Returns the new array of chunks.
_.chunk(['a', 'b', 'c', 'd'], 2);
// => [['a', 'b'], ['c', 'd']]

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

Lodash Cheat Sheet by simple cheat sheet

Top comments (1)

Collapse
 
saimwebhr profile image
Muhammad Saim Hashmi

@Lam Hoang what if I pass 0 or may be 6 as arguments?