By the end of this tutorial, you’ll use Lodash’s _.property() to build small getter functions that read nested object paths—then reuse them in map, sortBy, and your own code.
01
Core Syntax
_.property(path)
02
Dot paths
'address.city'
03
Array paths
['a','b']
04
Reusable fn
Call on many objects.
05
Iteratee
Works in map/sortBy.
06
vs get
Getter vs one-shot.
Fundamentals
What Is _.property()?
_.property(path) is a getter factory. You give it a property path once; it returns a function that reads that path from any object you pass in. Instead of writing (user) => user.address.city everywhere, you create const getCity = _.property('address.city') and call getCity(user).
💡
Beginner tip — path first, object second
Think of it as partial application for property access: the path is baked in; the object arrives later when you invoke the returned function.
Lodash uses this pattern internally. When you write _.map(users, 'name'), the string shorthand is converted to _.property('name') under the hood—the same idea you can use explicitly for clarity or dynamic paths.
Foundation
📝 Syntax
Pass a path as a dot string or key array:
javascript
_.property(path)
Syntax Rules
path — dot-path string ('a.b.c') or array of keys (['a','b','c']).
Return value — a function (object) => value that reads the path.
Missing paths — returns undefined; does not throw.
Nested access — resolves deep properties like _.get().
Iteratee shorthand — 'name' in _.map behaves like _.property('name').
Modern JS optional chaining (obj?.a?.b) reads inline; property shines when you need a reusable getter passed around.
Next in the series: _.propertyOf()—fix the object first, pass paths later.
Wrap Up
Conclusion
_.property() turns a property path into a tiny, reusable getter—perfect for functional-style data work with Lodash collections. Once you recognize the pattern, shorthands like _.map(list, 'name') become obvious sugar over the same idea.
Reach for _.get for one-shot reads with defaults; reach for _.propertyOf when the object is fixed and paths vary.
Name getters clearly: getCity, getPrice, getUserId
Reuse getters in map, sortBy, groupBy, and filter iteratees
Use array paths when key segments come from variables
Prefer explicit _.property('name') when teaching or reviewing code
Combine with _.map to pluck fields from object arrays
❌ Don’t
Call _.property(user, 'name')—path is the only argument to property
Expect a default value—property has no built-in fallback (use get)
Use property when you need equality checks—use matchesProperty
Assume it throws on missing keys—it returns undefined
Confuse with propertyOf—the curry order is opposite
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about _.property()
Use these points when you need reusable property accessors.
5
Core concepts
📦01
Getter fn
Path baked in.
Core
🔄02
Dot / array
Two path forms.
Syntax
✅03
Iteratee
map & sortBy.
Usage
📝04
undefined
Missing = safe.
Behavior
🛠05
vs get
Reuse vs once.
Compare
❓ Frequently Asked Questions
_.property(path) returns a new function. When you call that function with an object, Lodash reads the value at path and returns it—like a reusable getter for one field or nested path.
A dot-path string such as 'address.city', or an array of keys such as ['address', 'city']. Both resolve nested values the same way Lodash uses elsewhere for property paths.
The getter returns undefined. Lodash does not throw—similar to optional access. Use _.get(object, path, defaultValue) when you need a fallback default in one call.
_.get(user, 'address.city') reads immediately and returns the value. _.property('address.city') returns a function you can reuse—ideal for _.map, _.sortBy, and storing getters in variables.
_.property(path) fixes the path first: getCity = _.property('city'); getCity(user). _.propertyOf(object) fixes the object first: getPath = _.propertyOf(user); getPath('city'). Same data, opposite curry order.
Use it when you need a small, reusable accessor—plucking names from users, sorting by age, grouping by status, or building iteratees for Lodash collection methods.
Did you know?
Lodash docs show _.map(objects, _.property('a.b')) to pluck nested values— the same pattern powers string shorthands like _.sortBy(users, 'age') and _.groupBy(events, 'type') across the library.