getChunks()function

getChunks(items: Iterable<T>, size: number): Iterable<readonly T[]>
ParamType
itemsIterable<T>
The iterable to split into chunks. required
sizenumber
The maximum number of items per chunk. required
Return
Iterable<readonly T[]>
An iterable yielding arrays of up to size items.

Yield chunks of a given size.

  • The final chunk may contain fewer than size items.

Examples

Array.from(getChunks([1, 2, 3, 4, 5], 2)) // [[1, 2], [3, 4], [5]]