Skip to content
Agents tracked: 440 Downloads (7d): 202M down 19.5% GitHub stars: 10.4M Releases (7d): 607 Agent status: 3 with issuesSince last limit reset: Claude 28d · Codex 0d Updated Oct 21, 2026

Split arrays with _.partition

_.partition runs a test on every item and returns two arrays: items that passed and items that failed.

All Lodash examples Lodash: usage and stats

Split arrays with _.partition: screenshot of the example below running
The code below, running in Chromium on our server (Oct 12, 2026). Press Run to see it live and change it.

How it works

  1. Split with a function. _.partition(numbers, n => n % 2) returns a pair of arrays, odd numbers first and even numbers second, as in the docs sample. [1]
  2. Destructure the result. Because the result is always a two-item array, array destructuring gives both groups names in one line, like [active, inactive]. [1]
  3. Use a property name. Passing the string 'active' instead of a function tests that property on each user object. [1]

Run and edit it

It runs in your browser, in a sandboxed frame that cannot see this site; the packages load from esm.sh only after you press Run.

import _ from 'lodash';

// The sample from the Lodash homepage
const [odd, even] = _.partition([1, 2, 3, 4], (n) => n % 2);
console.log('odd: ', JSON.stringify(odd));
console.log('even:', JSON.stringify(even));

const users = [
  { name: 'Ada', active: true, points: 120 },
  { name: 'Linus', active: false, points: 45 },
  { name: 'Grace', active: true, points: 300 },
  { name: 'Ken', active: false, points: 80 },
  { name: 'Margaret', active: true, points: 15 },
];

// Property shorthand: tests user.active
const [active, inactive] = _.partition(users, 'active');
console.log('active users:  ', active.map((u) => u.name).join(', '));
console.log('inactive users:', inactive.map((u) => u.name).join(', '));

// Any function works as the test
const [short, long] = _.partition(users, (u) => u.name.length <= 4);
console.log('short names:', short.map((u) => u.name).join(', '));
console.log('long names: ', long.map((u) => u.name).join(', '));

console.log('original length unchanged:', users.length);
Ctrl/⌘ + Enter runs

Free for signed-in members, with a daily limit. Describe the change in plain words; the new code runs only in your browser.

Change the predicate, for example to n => n > 2, and watch both groups change. Code written by AgentGid [1].

Checked Oct 12, 2026: it starts without errors in Chromium with lodash 4.18.1. Needs WebGL.

More Lodash examples

Default values with _.defaults Read nested values with _.at Iterate collections with Lodash Compose functions with Lodash

Sources

  1. Lodash website

Explanations written by AgentGid from the official docs; the numbers in brackets point here. The code marked "written by AgentGid" is ours and free to copy.

Building something with Lodash? Ask AgentGid →