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.
Fundamentals
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.
Foundation
📝 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.
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
📤 Console output:
matchesProperty: both users
matches: John only
When to use which
Use matchesProperty for one path + value (especially nested dot paths). Use matches when several properties must match together.
Compare
📋 _.matchesProperty vs related patterns
Topic
_.matchesProperty
_.matches
_.property
[path, value]
Checks
One path vs value
Object pattern
Reads path only
Same as matchesProperty
Returns
Predicate boolean
Predicate boolean
Property value
Shorthand iteratee
Nested path
Dot or array path
Nested object keys
Dot or array path
First element = path
Best for
Single-field filter
Multi-key filter
Map / pluck
Inline filter
Example
('age', 30)
({ age: 30 })
('age')
['age', 30]
🧠 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).
Important
📝 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.
Wrap Up
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.
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
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about _.matchesProperty()
Use these points when matching a single property path.
5
Core concepts
📂01
Path + value
Two arguments.
Basics
🔎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.