# Chunk Array

Split array into chunks of specified size using lodash _.chunk

> Canonical page: https://elysiatools.com/en/tools/chunk-array

- **Category:** Data Processing

- **Keywords:** array, chunk, split, group, batch, lodash

## Overview

Split any array into smaller chunks (sub-arrays) of a specified size.

## Features:
- Accepts JSON arrays (numbers, strings, objects, or mixed types)
- Customizable chunk size (1-100 elements)
- Uses lodash _.chunk for reliable array processing
- Preserves array element types

## Examples:
- Input: [1, 2, 3, 4, 5], Size: 2 → [[1, 2], [3, 4], [5]]
- Input: ["a", "b", "c", "d", "e"], Size: 3 → [["a", "b", "c"], ["d", "e"]]
- Input: [1, "a", 2, "b"], Size: 2 → [[1, "a"], [2, "b"]]

## Use Cases:
- **Batch Processing**: Process arrays in batches for API calls
- **Pagination**: Split data into page-sized chunks
- **Data Organization**: Group related array elements
- **Memory Management**: Process large arrays in smaller pieces

## Inputs

- **Array Input** (textarea): Enter a valid JSON array to chunk
- **Chunk Size** (number): Number of elements per chunk (1-100)

## When to use

- When you need to process large arrays in batches for API calls to avoid rate limits or memory issues.
- When implementing pagination by dividing data into fixed-size chunks for display in web applications.
- When organizing related array elements into groups for efficient data analysis or management.

## How it works

- Enter a valid JSON array into the input textarea, such as \[1, 2, 3, 4, 5\] or \["a", "b", "c"\].
- Specify the chunk size using the number input, which must be between 1 and 100 elements per chunk.
- The tool applies the lodash _.chunk function to split the array into sub-arrays based on the size.
- Output is provided as a JSON array of arrays, where each inner array is a chunk from the original input.

## Use cases

- Batch API Processing: Split large datasets like user IDs into chunks to send multiple API requests in batches.
- Data Pagination: Divide a list of items, such as products or articles, into page-sized chunks for UI display.
- Memory-Efficient Processing: Handle large arrays by processing one chunk at a time to reduce memory usage.

## Frequently asked questions

### What types of arrays can I input?

You can input any valid JSON array, including numbers, strings, objects, or mixed types.

### What is the default chunk size?

The default chunk size is 2 elements per chunk.

### Can I chunk arrays with nested objects?

Yes, the tool preserves element types, so nested objects are handled correctly within chunks.

### Is there a limit to the array size I can process?

While there's no strict limit, very large arrays may depend on your browser or system memory for processing.

### How is the output formatted?

The output is a JSON array where each element is a sub-array (chunk) containing a portion of the original array.

## Related tools

- [Flatten Depth Array](https://elysiatools.com/en/tools/flatten-depth-array): Flatten array to specified depth using lodash _.flattenDepth
- [From Pairs](https://elysiatools.com/en/tools/from-pairs): Convert array of key-value pairs to object using lodash _.fromPairs
- [Without Values](https://elysiatools.com/en/tools/without-values): Remove specified values from an array using lodash _.without
- [Compact Array](https://elysiatools.com/en/tools/compact-array): Remove falsey values from array using lodash _.compact
- [Drop Items](https://elysiatools.com/en/tools/drop-items): Drop first N items from array using lodash _.drop
- [Drop Right Items](https://elysiatools.com/en/tools/drop-right-items): Drop last N items from array using lodash _.dropRight
- [Drop While](https://elysiatools.com/en/tools/drop-while): Drop items from array while predicate is true using lodash _.dropWhile
- [Fill Array](https://elysiatools.com/en/tools/fill-array): Fill array with value from start to end index using lodash _.fill

## Samples

- [Grafana Advanced Application Samples](https://elysiatools.com/en/samples/grafana-samples): Comprehensive Grafana samples covering advanced dashboard design, alerting configurations, data source integrations, and plugin development
- [QR Code Samples](https://elysiatools.com/en/samples/qrcode-samples): Sample QR code images for testing QR code reading and generation tools
- [D3.js Data Visualization Samples](https://elysiatools.com/en/samples/d3js-data-visualization): Comprehensive D3.js data visualization examples including charts, maps, animations, and interactive visualizations
- [Rome JavaScript Toolchain Samples](https://elysiatools.com/en/samples/rome): Rome JavaScript toolchain examples including configuration, linting, formatting, bundling, and project management
