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

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.

📝 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').
javascript
import property from "lodash/property";



const user = {

  name: "Ada",

  address: { city: "London" },

};



const getCity = property("address.city");



getCity(user);

// "London"

⚡ Quick Reference

TaskCode patternNotes
Nested getter_.property('address.city')Dot path
Array path_.property(['a','b'])Same as dot
Pluck names_.map(users, _.property('name'))Or 'name'
Sort by field_.sortBy(items, _.property('age'))Iteratee
Dynamic path_.property(fieldName)Variable path
One-shot read_.get(obj, path)No reusable fn
Returns
Function

Getter

Path
String | Array

Dot or keys

Missing
undefined

No throw

Category
Util

Iteratee

🧰 Parameters

Argument to _.property() and the getter it returns:

path Required

Property path as a dot string or array of keys. Targets one value at that location.

_.property('user.name')
dot string Form

Readable nested paths: 'address.zip', 'a.b.c'.

_.property('details.price')
key array Form

Equivalent array form when keys are dynamic or you avoid dot strings.

_.property(['address','city'])
returned fn Getter

Accepts one object (or value) and returns the resolved property value.

getCity(user)

To match a path to an expected value (predicate), use _.matchesProperty() instead of _.property().

Examples Gallery

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

📚 Getting Started

Create a getter for a nested field and call it on an object.

Example 1 — Nested dot path

Read address.city without repeating property chains.

javascript
const user = {

  id: 1,

  name: "John Doe",

  address: { city: "New York", zip: "10001" },

};



const getCity = _.property("address.city");



console.log(getCity(user));

// "New York"
Try It Yourself

How It Works

_.property('address.city') returns a function. Calling it with user walks the path and yields the city string.

Example 2 — Array path (same result)

Array keys are equivalent to dot notation—useful when segments are variables.

javascript
const user = {

  address: { city: "New York", zip: "10001" },

};



const getZipDot = _.property("address.zip");

const getZipArr = _.property(["address", "zip"]);



console.log(getZipDot(user));

console.log(getZipArr(user));

// "10001"

// "10001"

How It Works

Lodash resolves both forms through the same path logic used by _.get and iteratee shorthands.

📈 Practical Patterns

Collection helpers, sorting, and safe missing-path reads.

Example 3 — Pluck names with _.map

Official Lodash pattern—extract one field from every object in a list.

javascript
const users = [

  { name: "Ada", role: "admin" },

  { name: "Bob", role: "editor" },

];



const getName = _.property("name");



console.log(_.map(users, getName));

console.log(_.map(users, "name")); // string shorthand — same idea

// ["Ada", "Bob"]

// ["Ada", "Bob"]
Try It Yourself

How It Works

Pass the getter directly as the iteratee. Lodash calls it on each element—cleaner than inline arrow functions when you only need one field.

Example 4 — Sort by age with _.sortBy

Property getters work anywhere Lodash expects an iteratee.

javascript
const people = [

  { name: "Zara", age: 30 },

  { name: "Amy", age: 22 },

  { name: "Ben", age: 27 },

];



console.log(_.sortBy(people, _.property("age")));

// Amy (22), Ben (27), Zara (30)
Try It Yourself

How It Works

sortBy compares the values returned by the getter for each item—ascending by default.

Example 5 — Dynamic path and missing values

Build getters from runtime variables; missing paths return undefined without throwing.

javascript
const user = {

  address: { zip: "10001" },

};



const field = "address.zip";

const getField = _.property(field);



console.log(getField(user));

console.log(_.property("address.country")(user));

// "10001"

// undefined — no error

How It Works

For a default when missing, use _.get(user, 'address.country', 'N/A') on a one-off read—or wrap the getter yourself.

🚀 Beyond the Basics

property vs get vs propertyOf—the three related accessors.

Example 6 — property vs get vs propertyOf

Same data, three styles—pick based on whether you fix the path or the object first.

javascript
const product = { details: { price: 19.99 } };



// One-shot read — immediate value

console.log(_.get(product, "details.price"));



// Reusable getter — path fixed

const getPrice = _.property("details.price");

console.log(getPrice(product));



// Reusable reader — object fixed (see propertyOf tutorial)

const readFromProduct = _.propertyOf(product);

console.log(readFromProduct("details.price"));

// 19.99, 19.99, 19.99

When to use which

Many objects, one path → property. One object, many paths → propertyOf. Single read with optional default → get.

🧠 How _.property() Works

1

Capture path

Lodash stores the dot string or key array you passed in.

Setup
2

Return getter

A function ready to plug into map, sortBy, filter, or your own logic.

Factory
3

Resolve on call

When invoked with an object, walk the path and return the value (or undefined).

Read
=

Property value

The value at path on the given object—reusable every time you call the getter.

📝 Notes

  • _.property(path) returns a function—call it with an object: getCity(user), not _.property(user, 'city').
  • String iteratees in Lodash ('name', 'user.id') are shorthand for _.property(...).
  • Missing paths return undefined; use _.get() when you need a default in one expression.
  • For “does this field equal X?” use _.matchesProperty(), not property alone.
  • 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.

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.

💡 Best Practices

✅ Do

  • 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

Key Takeaways

Knowledge Unlocked

Five things to remember about _.property()

Use these points when you need reusable property accessors.

5
Core concepts
🔄 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.

Practice _.property() in the Live Editor

Try nested city getters, pluck names with map, and sort people by age.

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