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.
chunk(['a', 'b', 'c', 'd'], 2)
// => [['a', 'b'], ['c', 'd']]
chunk(['a', 'b', 'c', 'd'], 3)
// => [['a', 'b', 'c'], ['d']]
Name | Type | Attribute | Description |
---|---|---|---|
array | The array to process. | ||
size | The length of each chunk |
{ "comment": "/**\r\n * Creates an array of elements split into groups the length of `size`.\r\n * If `array` can't be split evenly, the final chunk will be the remaining\r\n * elements.\r\n *\r\n * @since 3.0.0\r\n * @category Array\r\n * @param {Array} array The array to process.\r\n * @param {number} [size=1] The length of each chunk\r\n * @returns {Array} Returns the new array of chunks.\r\n * @example\r\n *\r\n * chunk(['a', 'b', 'c', 'd'], 2)\r\n * // => [['a', 'b'], ['c', 'd']]\r\n *\r\n * chunk(['a', 'b', 'c', 'd'], 3)\r\n * // => [['a', 'b', 'c'], ['d']]\r\n */", "meta": { "range": [ 582, 953 ], "filename": "chunk.js", "lineno": 21, "path": "C:\\Users\\beaujeup\\projects\\jsdoc-template\\examples\\lodash\\lodash-repo", "code": { "id": "astnode100000424", "name": "chunk", "type": "FunctionDeclaration", "paramnames": [ "array", "size" ] }, "vars": { "size": "chunk~size", "length": "chunk~length", "index": "chunk~result.undefined].index", "resIndex": "chunk~resIndex", "result": "chunk~result", "result[undefined]": "chunk~result.undefined]" } }, "description": "Creates an array of elements split into groups the length of `size`.\rIf `array` can't be split evenly, the final chunk will be the remaining\relements.", "since": "3.0.0", "tags": [ { "originalTitle": "category", "title": "category", "text": "Array", "value": "Array" } ], "params": [ { "type": { "names": [ "Array" ] }, "description": "The array to process.", "name": "array" }, { "type": { "names": [ "number" ] }, "optional": true, "defaultvalue": 1, "description": "The length of each chunk", "name": "size" } ], "returns": [ { "type": { "names": [ "Array" ] }, "description": "Returns the new array of chunks." } ], "examples": [ "chunk(['a', 'b', 'c', 'd'], 2)\r// => [['a', 'b'], ['c', 'd']]\r\rchunk(['a', 'b', 'c', 'd'], 3)\r// => [['a', 'b', 'c'], ['d']]" ], "name": "chunk", "longname": "chunk", "kind": "function", "scope": "global", "___id": "T000002R000041", "___s": true, "filepath": "chunk.js" }