---
title: "chunk"
description: "Split an array into smaller arrays of a fixed size, returning a new array of chunks without mutating the original input array."
canonical_url: "https://core.mhaibaraai.cn/en/docs/utilities/array/chunk"
---
# chunk

> Split an array into smaller arrays of a fixed size, returning a new array of chunks without mutating the original input array.

## Usage

`chunk` splits an array into multiple sub-arrays of a given size. Commonly used for pagination, batch processing, and data partitioning.

```ts
import { chunk } from '@movk/core'

const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9]
const chunks = chunk(numbers, 3)
console.log(chunks) // [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

const names = ['Alice', 'Bob', 'Charlie', 'David', 'Eve']
const pairs = chunk(names, 2)
console.log(pairs) // [['Alice', 'Bob'], ['Charlie', 'David'], ['Eve']]
```

## API

### `chunk<T>(arr, size)`

Split an array into chunks of the specified size.

### Parameters

**arr** (`T[]`) *required*: The array to split.

**size** (`number`) *required*: The size of each chunk.

### Returns

**returns** (`T[][]`): A two-dimensional array where each sub-array has at most size elements.

## Changelog

See commit history for [src/utilities/array/chunk.ts](https://github.com/mhaibaraai/movk-core/commits/main/src/utilities/array/chunk.ts).

---

- [GitHub](https://github.com/mhaibaraai/movk-core/blob/main/src/utilities/array/chunk.ts)


## Sitemap

See the full [sitemap](https://core.mhaibaraai.cn/sitemap.md) for all pages.
