Chunk

Chunk an array into smaller arrays of a specified size.

CategoryArrays
AuthorPol Gubau
Since1.0.0
Last Updated2025-03-15
TypeSync
CompatibilityUniversal

Example

  • Input

    chunk([1, 2, 3, 4, 5], 2)

    Output:

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

Return

An array of smaller arrays of the specified size.

Type: array[]

Props

NameTypeDefaultRequiredDescription
dataT[]nullYesThe array to be chunked.
sizenumber10NoThe size of each chunk.

Notes

If the array length is not a multiple of size, the last chunk may be smaller.

Tags

  • array
  • chunk
  • split

Related