Date

“Array” Methods

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

source npm package

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.

引入版本

3.0.0

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

返回值
(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']]