Lodash _.partition() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Collection

Definition

Creates an array of elements split into two groups: the first holds elements the predicate returns truthy for, the second holds the rest. Part of Lodash 4.x Collection.

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

Syntax

Call _.partition on a collection. Start with this line.

Lodash
_.partition(collection, [predicate=_.identity])
CallWhat it does
_.partition(collection, [predicate=_.identity])Primary signature.
_.partition(collection)Call with a collection argument.

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

Library declarations
Lodash
_.partition(collection, [predicate=_.identity])

Parameters

ParameterDescription
collectionRequired. Array or object to split
predicateOptional. Function or iteratee shorthand; default identity

Return Value

Return ValueDescription
*[passArray, failArray] — always length 2

Lodash Examples

Example 1 — Even and Odd Numbers

A function predicate puts even numbers in the first bucket.

Lodash
_.partition([1, 2, 3, 4], function (n) {
  return n % 2 === 0;
});
// → [[2, 4], [1, 3]]
Try It Yourself

How It Works

  1. Source. Numbers 1 … 4.
  2. Test. n % 2 === 0 is truthy for evens.
  3. Pass bucket. 2 and 4 land in index 0.
  4. Fail bucket. Odds stay in index 1, in original order.

Example 2 — Official: Property Shorthand

A string iteratee reads that property — truthy values go first.

Lodash
var users = [
  { user: "barney",  active: false },
  { user: "fred",    active: true },
  { user: "pebbles", active: false }
];

_.partition(users, "active");
// → [[{ user: "fred", active: true }],
//     [{ user: "barney", … }, { user: "pebbles", … }]]
Try It Yourself

How It Works

  1. Shorthand. "active" means read each object’s .active.
  2. Truthy hit. Only fred has active: true.
  3. Falsy hits. barney and pebbles go to the second array.
  4. Same as. function (o) { return o.active; }.

Example 3 — Official: Matcher Object

Objects that deeply match the partial shape land in the first bucket.

Lodash
var users = [
  { user: "barney",  age: 36, active: false },
  { user: "fred",    age: 40, active: true },
  { user: "pebbles", age: 1,  active: false }
];

_.partition(users, { age: 1, active: false });
// → [[{ user: "pebbles", age: 1, active: false }],
//     [{ user: "barney", … }, { user: "fred", … }]]
Try It Yourself

How It Works

  1. Matcher. Lodash treats the object as a partial match (_.matches).
  2. Only pebbles. Matches both age: 1 and active: false.
  3. Others. barney and fred fail the full match → second bucket.
  4. Use. Handy when several fields define “yes”.

Example 4 — Official: matchesProperty Pair

Pass [path, value] to test one property against a target.

Lodash
var users = [
  { user: "barney",  active: false },
  { user: "fred",    active: true },
  { user: "pebbles", active: false }
];

_.partition(users, ["active", false]);
// → [[{ user: "barney", … }, { user: "pebbles", … }],
//     [{ user: "fred", active: true }]]
Try It Yourself

How It Works

  1. Pair. ["active", false] means “is active equal to false?”.
  2. Pass. barney and pebbles match → first array.
  3. Fail. fred has active: true → second array.
  4. Flip. Compared with example 2, truthy/falsy buckets are inverted because the test targets false.

Example 5 — Empty Fail Bucket

When every element matches, the second array is still present — just empty.

Lodash
_.partition([2, 4, 6], function (n) {
  return n % 2 === 0;
});
// → [[2, 4, 6], []]
Try It Yourself

How It Works

  1. All even. Every number satisfies the predicate.
  2. Pass. All three go to index 0.
  3. Fail. Index 1 is [] — not omitted.
  4. Safe. Destructuring const [pass, fail] = … always works.

Browser & Runtime Support

_.partition is a Lodash 4.x Collection 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

_.partition()

Available in [email protected] full builds and the lodash/partition 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
_.partition Lodash 4.x+

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

Frequently Asked Questions

_.partition(collection, predicate) splits elements into two arrays: those where the predicate is truthy, then those where it is falsy. It returns [pass, fail] and does not mutate the source.
No. It builds two new arrays. Object elements are still shared by reference — partitioning does not deep-clone.
filter and reject each walk the collection (predicate runs twice). partition walks once and fills both buckets.
Yes. Property names, matchers, and matchesProperty pairs work like other Lodash collection helpers — same as the official docs.
You still get two arrays. One may be []. The tuple length is always 2.
Use import partition from "lodash/partition" or require("lodash/partition") for tree-shaking. Full build: import _ from "lodash" then _.partition.

Next: _.reduce()

Fold a collection into a single accumulated value.

_.reduce() 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