Skip to content

chunk

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

创建一个元素数组,这些元素分成长度为 size 的组。如果 array 不能均匀分割,则最后的块将是剩余的元素。

¥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.

新增于

¥Since

3.0.0

参数

¥Arguments

  1. array (数组):要处理的数组。

    ¥array (Array): The array to process.

  2. [size=1] (数值):每个块的长度

    ¥[size=1] (number): The length of each chunk

返回

¥Returns

(数组):返回新的块数组。

¥(Array): Returns the new array of chunks.

示例

¥Example

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

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

Lodash v4.17 中文网 - 粤ICP备13048890号