For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /reference/array/chunk.md.

chunk es-toolkit

Splits an array into smaller arrays of a specified size.

const chunked = chunk(arr, size);

Usage

chunk(arr, size)

Use chunk when you want to split a long array into multiple smaller arrays of the same size. If the array cannot be evenly divided, the last chunk will contain the remaining elements.

import { chunk } from 'es-toolkit/array';

// Split a number array into chunks of size 2.
chunk([1, 2, 3, 4, 5], 2);
// Returns: [[1, 2], [3, 4], [5]]

// Split a string array into chunks of size 3.
chunk(['a', 'b', 'c', 'd', 'e', 'f', 'g'], 3);
// Returns: [['a', 'b', 'c'], ['d', 'e', 'f'], ['g']]

Splitting an empty array returns an empty array.

import { chunk } from 'es-toolkit/array';

chunk([], 2); // []

Parameters

arrT[]required

The array to split.

sizenumberrequired

The size of each chunk. Must be a positive integer.

Returns

A 2D array split into chunks of size size.

T[][]

Throws

Throws an error if size is not a positive integer.

Try It

::: sandpack

import { chunk } from 'es-toolkit/array';

console.log(chunk([1, 2, 3, 4, 5], 2));

:::

Source: es-toolkit

Re-exported verbatim from es-toolkit. Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.