FunctionIdentifies the base type of array elements
The array or array-like object to chunk
The size of each chunk. Must be a positive integer
A new array of chunks, where each chunk is an array of the specified size
arrChunk([1, 2, 3, 4, 5, 6, 7], 2); // [[1, 2], [3, 4], [5, 6], [7]]
arrChunk([1, 2, 3, 4, 5], 3); // [[1, 2, 3], [4, 5]]
arrChunk([1, 2, 3], 1); // [[1], [2], [3]]
arrChunk([1, 2, 3], 5); // [[1, 2, 3]]
arrChunk([], 2); // []
// Array-like objects
arrChunk({ length: 5, 0: "a", 1: "b", 2: "c", 3: "d", 4: "e" }, 2);
// [["a", "b"], ["c", "d"], ["e"]]
The arrChunk() method returns a new array with elements divided into groups of a specified size. The last group may have fewer elements if the array length is not divisible by the chunk size.