Lodash _.filter() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Collection

Definition

Iterates a collection and returns a new array of every element whose predicate is truthy. Unlike _.remove, it does not mutate the source. Part of Lodash 4.x Collection (since 0.1.0).

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

Syntax

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

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

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

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

Parameters

ParameterDescription
collectionRequired. Array or object to scan
predicateOptional. Keep when truthy; default _.identity

Return Value

Return ValueDescription
*New array of matches

Lodash Examples

Example 1 — Official: Function Predicate

Keep users where active is false.

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

_.filter(users, function (o) {
  return !o.active;
});
// → [{ user: "fred", age: 40, active: false }]
Try It Yourself

How It Works

  1. Predicate. Returns true when the user is inactive.
  2. Barney. active is true → skipped.
  3. Fred. active is false → kept.
  4. New array. Source users is unchanged.

Example 2 — Official: matches Shorthand

Match objects that deep-equal the partial shape.

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

_.filter(users, { age: 36, active: true });
// → [{ user: "barney", age: 36, active: true }]
Try It Yourself

How It Works

  1. Shorthand. Object means “must match these fields”.
  2. Barney. age 36 and active true → kept.
  3. Fred. Different age/active → skipped.
  4. Extra fields. user need not appear in the match object.

Example 3 — Official: matchesProperty Shorthand

Keep rows where one property equals a value.

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

_.filter(users, ["active", false]);
// → [{ user: "fred", age: 40, active: false }]
Try It Yourself

How It Works

  1. Pair. ["active", false] means property equals value.
  2. Barney. active is true → skipped.
  3. Fred. Matches → kept.
  4. Handy. Same idea as a tiny equality guard.

Example 4 — Official: Property Shorthand

Keep elements whose named property is truthy.

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

_.filter(users, "active");
// → [{ user: "barney", age: 36, active: true }]
Try It Yourself

How It Works

  1. Shorthand. "active" reads that property as the test.
  2. Barney. Truthy active → kept.
  3. Fred. Falsey → skipped.
  4. Compact. Ideal for boolean flags on rows.

Example 5 — Filter Numbers

Keep only values above a threshold.

Lodash
_.filter([5, 12, 8, 20, 3], function (n) {
  return n > 10;
});
// → [12, 20]
Try It Yourself

How It Works

  1. Guard. Function returns whether n > 10.
  2. Pass. 12 and 20 are kept.
  3. Skip. 5, 8, and 3 are dropped.
  4. Order. Matches stay in original sequence.

Browser & Runtime Support

_.filter is a Lodash 4.x Collection helper (since 0.1.0). It runs anywhere Lodash runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install lodash. Native Array.prototype.filter covers arrays only; Lodash also walks plain objects and offers iteratee shorthands.

✓ Stable · Lodash 4.x

_.filter()

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

Bottom line: Safe for production once Lodash is loaded. Prefer import filter from "lodash/filter" for smaller builds. Ideal for search results, status lists, and UI table filters.

Frequently Asked Questions

_.filter(collection, predicate) returns a new array of every element for which predicate is truthy. Order matches collection order.
No. Unlike _.remove, filter always returns a new array and leaves the source unchanged.
An array of matching values — not an object. Keys are not preserved in the result shape.
filter keeps truthy predicate results. reject keeps falsey ones — the complement with the same iteratee.
partition returns [pass, fail] in one pass. filter only returns the pass list.
Use import filter from "lodash/filter" or require("lodash/filter") for tree-shaking. Full build: import _ from "lodash" then _.filter.

Next: _.find()

Return the first element that passes a predicate — or undefined.

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