chunk
chunk<T>(array: T[], size: number): T[][]Source: array.ts:105
Chunks an array into smaller arrays of a specified size
Type Parameters
T— Array element type
Parameters
array(T[]) — The input arraysize(number) — Size of each chunk
Returns
T[][]— Array of chunks
Throws
- Error If size is less than 1
Example
CODE
chunk([1, 2, 3, 4, 5], 2)
// [[1, 2], [3, 4], [5]]