Lodash _.matches() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Util

Definition

Creates a predicate that performs a partial deep comparison against a source object — true when the given object has equivalent values for every listed key. Part of Lodash Util since 3.0.0 (stable — not deprecated).

Note: Equivalent to _.isMatch with source partially applied. Extra keys on the object are ignored.

Syntax

Call _.matches. Start with this line.

Lodash
_.matches(source)
CallWhat it does
_.matches(source)Primary signature.
_.matches(...)Call the util helper.

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

Library declarations
Lodash
_.matches(source)

Parameters

ParameterDescription
sourceRequired. Object of property values to match

Return Value

Return ValueDescription
*Predicate function (object) → boolean

Lodash Examples

Example 1 — Official: Filter by Partial Match

Keep objects whose listed keys match the source pattern.

Lodash
var objects = [
  { 'a': 1, 'b': 2, 'c': 3 },
  { 'a': 4, 'b': 5, 'c': 6 }
];

_.filter(objects, _.matches({ 'a': 4, 'c': 6 }));
// → [{ 'a': 4, 'b': 5, 'c': 6 }]
Try It Yourself

How It Works

  1. Pattern. Source requires a === 4 and c === 6.
  2. First row. a is 1 → fails.
  3. Second row. Both keys match; b is ignored.
  4. Result. Only the second object remains.

Example 2 — Call the Predicate Directly

Same rules as _.isMatch(object, source), as a reusable function.

Lodash
var isMatchAC = _.matches({ a: 4, c: 6 });

isMatchAC({ a: 4, b: 5, c: 6 });
// → true

isMatchAC({ a: 1, b: 2, c: 3 });
// → false

_.isMatch({ a: 4, b: 5, c: 6 }, { a: 4, c: 6 });
// → true  // same comparison
Try It Yourself

How It Works

  1. Factory. Build the predicate once from source.
  2. Pass. First object has matching a and c → true.
  3. Fail. Second object’s a differs → false.
  4. Alias. _.isMatch is the one-shot form of the same check.

Example 3 — Object Shorthand (No Wrap)

Collection methods already treat plain objects as matches predicates.

Lodash
var objects = [
  { 'a': 1, 'b': 2, 'c': 3 },
  { 'a': 4, 'b': 5, 'c': 6 }
];

_.filter(objects, { 'a': 4, 'c': 6 });
// → [{ 'a': 4, 'b': 5, 'c': 6 }]

_.filter(objects, _.matches({ 'a': 4, 'c': 6 }));
// → same result
Try It Yourself

How It Works

  1. Shorthand. Passing an object to _.filter is enough.
  2. Under the hood. Lodash converts it via _.iteratee → matches.
  3. Explicit. Wrap with _.matches when you reuse the predicate.
  4. Same rules. Both paths use partial deep comparison.

Example 4 — Empty Source Values

Official note: empty {} / [] in source match any object / array.

Lodash
var matchAnyObj = _.matches({ meta: {} });

matchAnyObj({ meta: { x: 1 } });
// → true

matchAnyObj({ meta: {} });
// → true

matchAnyObj({ meta: null });
// → false
Try It Yourself

How It Works

  1. Empty object. {} in source means “any object here.”
  2. Filled / empty. Both {x:1} and {} pass.
  3. Not an object. null fails the object check.
  4. Warning. Easy to over-match if you leave empty nests in source.

Example 5 — Official: Several Possible Values

Combine matchers with _.overSome for OR-style patterns.

Lodash
var objects = [
  { 'a': 1, 'b': 2, 'c': 3 },
  { 'a': 4, 'b': 5, 'c': 6 }
];

_.filter(objects, _.overSome([
  _.matches({ 'a': 1 }),
  _.matches({ 'a': 4 })
]));
// → both objects
Try It Yourself

How It Works

  1. Two patterns. Match a:1 or a:4.
  2. OR helper. _.overSome returns true if any matcher passes.
  3. Both rows. Each object satisfies one branch.
  4. Use. Official way to check several possible values.

Browser & Runtime Support

_.matches is a Lodash Util helper since 3.0.0. It runs anywhere Lodash 3+ / 4.x runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install lodash.

✓ Stable · Lodash 3.0.0+

_.matches()

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

100% With Lodash 3.0+
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
_.matches Lodash 3.0.0+

Bottom line: Safe for production once Lodash is loaded. Prefer import matches from "lodash/matches" for smaller bundles. Collection methods already accept object shorthands with the same rules.

Frequently Asked Questions

_.matches(source) returns a predicate. Call it with an object and it returns true if that object partially matches source—a deep comparison on every key listed in source. Extra properties on the object do not fail the match.
They use the same comparison. _.isMatch(object, source) checks once. _.matches(source) returns a reusable function equivalent to _.isMatch with source partially applied.
Yes. _.filter(objects, { a: 4, c: 6 }) uses the same rules as _.filter(objects, _.matches({ a: 4, c: 6 })). Use _.matches() when you need to store or reuse the predicate.
Yes. Official note: empty object and empty array source values match any object or array value respectively. Be careful with {} or [] in your source pattern.
_.matches() compares fixed values with partial deep equality. _.conforms() runs a predicate function per key—better for ranges, types, or custom checks.
Combine matchers with _.overSome, e.g. _.overSome([_.matches({a:1}), _.matches({a:4})]). That keeps objects matching any of the patterns.

Next: _.matchesProperty()

Check that one path equals a value — the path-pair iteratee shorthand.

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