Lodash _.matchesProperty() Method

Beginner
⏱️ 8 min read
📚 Updated: Jul 2026
🎯 6 Examples + 3 Try It
Util utilities

What You’ll Learn

By the end of this tutorial, you’ll build single-field matchers with Lodash’s _.matchesProperty()—path plus expected value—and use them in filter, find, and some.

01

Core Syntax

_.matchesProperty(path, value)

02

Dot Paths

'user.name' for nested fields.

03

Array Paths

['user', 'name'] equivalent form.

04

Shorthand

['status', 'active'] in filter.

05

vs matches

One path vs object pattern.

06

vs property

Compare vs pluck getter.

What Is _.matchesProperty()?

_.matchesProperty() creates a predicate that checks one property path against one expected value. Lodash resolves the path on each object (like _.get), then compares the result to your value using deep equality.

💡
Beginner tip — one field at a time

_.matchesProperty('age', 30) is the reusable form of “does this object’s age equal 30?” Use _.matches() when you need several keys at once.

You will also see the compact iteratee form: _.filter(users, ['status', 'active']). That two-element array is shorthand for the same path + value check.

📝 Syntax

Supply a path and the value you expect at that path:

javascript
_.matchesProperty(path, value)

Syntax Rules

  • path — string dot-path, array of keys, or path accepted by Lodash getters.
  • value — expected value at that path; compared with deep equality.
  • Return value — predicate (object) => boolean.
  • Shorthand[path, value] in _.filter / _.find uses the same rules.
  • Missing path — if the path resolves to undefined, match fails unless value is also undefined.
javascript
import matchesProperty from "lodash/matchesProperty";



const users = [

  { id: 1, name: "John", age: 30 },

  { id: 2, name: "Jane", age: 25 },

];



const isThirty = matchesProperty("age", 30);



_.filter(users, isThirty);

// [{ id: 1, name: 'John', age: 30 }]

⚡ Quick Reference

TaskCode patternNotes
Build predicate_.matchesProperty('age', 30)Reusable fn
Nested path_.matchesProperty('user.name', 'A')Dot notation
Array path_.matchesProperty(['user','name'], 'A')Same as dot
Filter shorthand_.filter(arr, ['status', 'active'])Iteratee form
Find one_.find(arr, _.matchesProperty('id', 2))First match
Pluck only_.property('age')No comparison
Returns
Function

Predicate

Checks
1 path

Single field

Compare
Deep

Lodash equality

Category
Util

Matching

🧰 Parameters

Arguments to _.matchesProperty() and how the predicate behaves:

path Required

Property path on each object. Use a string ('status', 'user.name') or key array (['user', 'name']).

_.matchesProperty("role", "admin")
value Required

Expected value at path. Type must match what you store—string '30' does not match number 30.

_.matchesProperty("age", 30)
returned fn Predicate

Called as predicate(object). Resolves path, compares to value, returns boolean.

const ok = isActive(record)
shorthand [path, value]

Pass a two-element array directly to collection methods instead of calling _.matchesProperty first.

_.filter(arr, ["status", "active"])

For multi-key object patterns, use _.matches(). To read a path without comparing, use _.property(path).

Examples Gallery

Practical _.matchesProperty() patterns with copy-ready code, sample output, and interactive Try It Yourself labs.

📚 Getting Started

Filter and match on a single top-level property.

Example 1 — Filter by age

Keep users whose age equals 30.

javascript
const users = [

  { id: 1, name: "John", age: 30 },

  { id: 2, name: "Jane", age: 25 },

  { id: 3, name: "Bob", age: 35 },

];



console.log(_.filter(users, _.matchesProperty("age", 30)));

// [{ id: 1, name: 'John', age: 30 }]
Try It Yourself

How It Works

Equivalent to (user) => user.age === 30 for primitives—Lodash uses deep equality for objects and arrays at the path.

Example 2 — Dot-path on nested data

Match user.name without building a nested matcher object.

javascript
const rows = [

  { user: { id: 1, name: "John" } },

  { user: { id: 2, name: "Alice" } },

  { user: { id: 3, name: "Bob" } },

];



console.log(_.filter(rows, _.matchesProperty("user.name", "Alice")));

// [{ user: { id: 2, name: 'Alice' } }]
Try It Yourself

How It Works

With _.matches() you would write { user: { name: 'Alice' } }. matchesProperty is cleaner for one nested field.

📈 Practical Patterns

Array paths, shorthand syntax, and find.

Example 3 — Array path form

Same check using a key array instead of a dot string.

javascript
const rows = [

  { user: { id: 1, name: "John" } },

  { user: { id: 2, name: "Alice" } },

];



const byDot = _.matchesProperty("user.name", "Alice");

const byArray = _.matchesProperty(["user", "name"], "Alice");



console.log(_.filter(rows, byDot));

console.log(_.filter(rows, byArray));

// same result both times

How It Works

Prefer array paths when the path is built dynamically from variables.

Example 4 — Two-element array shorthand

Skip _.matchesProperty when passing the iteratee inline.

javascript
const users = [

  { id: 1, name: "John", status: "active" },

  { id: 2, name: "Alice", status: "inactive" },

  { id: 3, name: "Bob", status: "active" },

];



const explicit = _.filter(users, _.matchesProperty("status", "active"));

const shorthand = _.filter(users, ["status", "active"]);



console.log(explicit);

console.log(shorthand);

// both return John and Bob
Try It Yourself

How It Works

Lodash iteratee rules treat [path, value] as matchesProperty. Store explicit predicates when reusing across files.

🚀 Beyond the Basics

Find, some, and comparison with related helpers.

Example 5 — Find and some

Locate one record or test whether any item matches.

javascript
const users = [

  { id: 1, name: "John", age: 30 },

  { id: 2, name: "Alice", age: 25 },

  { id: 3, name: "Bob", age: 35 },

];



console.log(_.find(users, _.matchesProperty("age", 25)));

// { id: 2, name: 'Alice', age: 25 }



console.log(_.some(users, _.matchesProperty("role", "admin")));

// false — no user has role: 'admin'

How It Works

Missing properties do not match unless the expected value is undefined. The old UI example using _.some(users, _.matchesProperty('role', 'admin')) correctly returns false when no admin exists.

Example 6 — matchesProperty vs matches

Choose the right matcher for single-field vs multi-field checks.

javascript
const users = [

  { id: 1, name: "John", status: "active" },

  { id: 2, name: "Jane", status: "active" },

];



// One field — matchesProperty (or shorthand)

_.filter(users, _.matchesProperty("status", "active"));



// Two fields — matches object pattern

_.filter(users, _.matches({ status: "active", name: "John" }));

// only John

When to use which

Use matchesProperty for one path + value (especially nested dot paths). Use matches when several properties must match together.

🧠 How _.matchesProperty() Works

1

Store path + value

Lodash closes over the path and expected value you pass in.

Setup
2

Resolve path

On each object, read the value at path (same resolution as _.get).

Lookup
3

Deep compare

Compare resolved value to expected value with Lodash equality semantics.

Compare
=

true or false

Match at path → true. Mismatch or missing path → false (unless value is undefined).

📝 Notes

  • _.matchesProperty checks one path—use _.matches for multi-key patterns.
  • Dot strings like 'user.name' traverse nested objects; they are not a single literal key name.
  • _.filter(arr, ['key', val]) is shorthand—same behavior as explicit matchesProperty.
  • Watch types: 30 (number) and '30' (string) are not equal.
  • _.property(path) extracts values; it does not compare to an expected value.
  • Next in the series: _.method() for invoking object methods by name.

Conclusion

_.matchesProperty() builds a predicate for “value at path equals expected”— ideal for filtering and finding by one field, including nested dot paths.

Use the [path, value] shorthand for quick filters, store explicit predicates when reusing, and switch to _.matches() when multiple keys must match.

💡 Best Practices

✅ Do

  • Use dot paths for one nested field instead of nested matcher objects
  • Store _.matchesProperty(path, value) for reusable filters
  • Use array paths when building paths dynamically
  • Pair with _.find, _.filter, and _.some
  • Match value types exactly (string vs number)

❌ Don’t

  • Use matchesProperty when you need several keys—use matches
  • Confuse with _.property, which only plucks values
  • Assume wrong path returns true—it resolves to undefined and fails
  • Use three-element arrays expecting matchesProperty—need exactly two elements
  • Rely on UI-only pseudo-code—test predicates on real data shapes

Key Takeaways

Knowledge Unlocked

Five things to remember about _.matchesProperty()

Use these points when matching a single property path.

5
Core concepts
🔎 02

Dot paths

Nested fields.

Practical
📊 03

Shorthand

[path, value].

Iteratee
🔄 04

vs property

Compare vs get.

Compare
05

matches

Multi-key patterns.

Related

❓ Frequently Asked Questions

_.matchesProperty(path, value) returns a predicate function. For each object, Lodash reads the value at path (using _.get-style resolution) and compares it to value with deep equality. Returns true when they match.
A dot-path string like 'user.name', an array of keys like ['user', 'name'], or any path form accepted by Lodash property resolution. The path targets one field—not a nested pattern object like _.matches().
_.matches({ status: 'active' }) checks multiple keys with partial object matching. _.matchesProperty('status', 'active') checks one path against one value—better when you care about a single field.
_.filter(arr, ['status', 'active']) uses the same rules as _.filter(arr, _.matchesProperty('status', 'active')). The two-element array is iteratee shorthand for path + expected value.
_.property('age') returns a getter—it plucks the value. _.matchesProperty('age', 30) returns a predicate that returns true only when the value at 'age' equals 30.
Use it to filter or find records by one field (status, role, id, nested user.name), build reusable single-field matchers, and express path+value checks readably in _.filter, _.find, and _.some.
Did you know?

The two-element array iteratee ['status', 'active'] is one of Lodash’s most compact filter forms—it is exactly how _.iteratee builds a matchesProperty callback under the hood.

Practice _.matchesProperty() in the Live Editor

Open the Try It editor, run the examples, and filter data by property paths.

Open Try It editor →

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.

6 people found this page helpful