Lodash _.chunk() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Array

Definition

Creates an array of elements split into groups the length of size. If the array cannot be split evenly, the final chunk holds the remaining elements. Part of Lodash 4.x Array.

Pass the required arguments shown below. Lodash Array helpers usually return a new value — check whether the source array is mutated.

Syntax

Call _.chunk on an array. Start with this line.

Lodash
_.chunk(array, [size=1])
CallWhat it does
_.chunk(array, [size=1])Primary signature.
_.chunk(array)Call with an array argument.

Prefer import chunk from "lodash/chunk" when you want a smaller bundle.

Library declarations
Lodash
_.chunk(array, [size=1])

Parameters

ParameterDescription
arrayRequired. Source to split
sizeOptional. Chunk length; default 1

Return Value

Return ValueDescription
*New array of chunk arrays

Lodash Examples

Example 1 — Official: Even Split

When length is a multiple of size, every chunk has the same length.

Lodash
_.chunk(["a", "b", "c", "d"], 2);
// → [["a", "b"], ["c", "d"]]
Try It Yourself

How It Works

  1. Source. Four letters; indexes 0 … 3.
  2. First group. Size 2 takes "a" and "b".
  3. Second group. Next two → "c" and "d".
  4. Even fit. No remainder — both chunks length 2.

Example 2 — Official: Shorter Last Chunk

Leftover elements stay in the final group.

Lodash
_.chunk(["a", "b", "c", "d"], 3);
// → [["a", "b", "c"], ["d"]]
Try It Yourself

How It Works

  1. First chunk. Take three items: a,b,c.
  2. Remainder. One item left → alone in the last chunk.
  3. Outer length. ceil(4 / 3) = 2.
  4. Rule. The last chunk is allowed to be shorter than size.

Example 3 — Default Size 1

Omit size and each element becomes its own chunk.

Lodash
_.chunk(["x", "y", "z"]);
// → [["x"], ["y"], ["z"]]
Try It Yourself

How It Works

  1. Default. Missing size means 1.
  2. Wrap. Each value is placed in its own inner array.
  3. Outer length. Equals the source length.
  4. Use. Rarely needed alone — useful when an API expects nested groups.

Example 4 — Empty Array

Chunking nothing yields an empty outer array.

Lodash
_.chunk([], 3);
// → []
Try It Yourself

How It Works

  1. Empty source. No elements to group.
  2. Result. Lodash returns [] — not [[]].
  3. Safe. No throw; loops over the result simply do nothing.
  4. Guard. Check result.length before assuming batches exist.

Example 5 — Size Larger Than Length

One chunk contains the whole array.

Lodash
_.chunk([10, 20, 30], 10);
// → [[10, 20, 30]]
Try It Yourself

How It Works

  1. Ask for 10. Source only has 3 items.
  2. One pass. All items fit in the first (and only) chunk.
  3. Outer length. ceil(3 / 10) = 1.
  4. Tip. Oversized size is fine — you still get a nested array.

Browser & Runtime Support

_.chunk is a Lodash 4.x Array helper. It runs anywhere Lodash runs — modern browsers (via CDN or bundle) and Node.js / Bun / Deno with npm install lodash.

✓ Stable · Lodash 4.x

_.chunk()

Available in [email protected] full builds and the lodash/chunk modular import. Works in evergreen browsers and current Node LTS when Lodash is installed.

100% With Lodash 4.x
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
_.chunk Lodash 4.x+

Bottom line: Safe for production once Lodash is on the page or in your bundle. Prefer import chunk from "lodash/chunk" for smaller builds. Not a native browser API — load Lodash first.

Frequently Asked Questions

_.chunk(array, size) splits an array into groups of length size. It returns a new array of those groups. If the length is not divisible by size, the last group holds the remaining elements.
No. It returns a new outer array of chunk arrays. The source array is left unchanged. Object elements inside are still shared by reference — chunking does not deep-clone.
When size is omitted, Lodash defaults to 1 — each element becomes its own one-item chunk.
_.chunk([], size) returns []. There are no inner arrays.
Use import chunk from "lodash/chunk" or require("lodash/chunk") so bundlers can tree-shake unused Lodash code. Full build: import _ from "lodash" then _.chunk.
Yes for in-memory batches (UI pages, API workers). For database pagination you still need LIMIT/OFFSET or cursors at the query layer — chunk only reshapes arrays you already hold.

Next: _.compact()

Remove falsy values and keep a clean array for the next step.

_.compact() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful