Skip to main content

ArrayChunk

Takes an array and splits it into smaller arrays (chunks) of a defined size. The last chunk may contain fewer elements if the array length is not evenly divisible by the chunk size.

Reference

Parameters

array
list

The array to be split into chunks.

Component data2-core-primitives@String

size

The size of each chunk.

Component data2-core-primitives@Number

Example

Input

[1, 2, 3, 4, 5]

Size: 2

Output:

[[1, 2], [3, 4], [5]]

Note: If the array length is not evenly divisible by the defined size, the last chunk will contain only the remaining elements, which may be fewer than the specified size.