Lodash _.result() Method

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

What You’ll Learn

By the end of this tutorial, you’ll use _.result() to read nested values, call object methods safely, and fall back to defaults when data is missing.

01

Path resolution

Read properties with dot paths or key arrays.

02

Auto-invoke

Functions at the path run with the parent as this.

03

Defaults

Return a fallback when the resolved value is undefined.

04

Lazy defaults

Pass a function as defaultValue for computed fallbacks.

05

result vs get

Know when to invoke methods vs plain reads.

06

Production tips

Avoid confusing null, missing paths, and method side effects.

What Is _.result()?

_.result() resolves a property on an object—including nested paths—and returns the final value. If the value at that path is a function, Lodash calls it with the parent object as this and returns what the function returns. If the resolved value is undefined, the optional defaultValue is used instead.

💡
How it differs from _.get()

_.get(user, "greet") returns the function itself. _.result(user, "greet") runs the function and gives you the greeting string.

Reach for _.result() when objects expose computed values as methods, when paths may be missing, or when you want a clean default without manual if checks.

📝 Syntax

The signature combines an object, a path, and an optional default:

javascript
_.result(object, path, [defaultValue])

Syntax Rules

  • object — the object to query.
  • path — property path as a string ("a.b"), array (["a", "b"]), or single key.
  • Function at path — invoked with parent object as this; its return value is the result.
  • undefined resolved — returns defaultValue (if default is a function, it is invoked with parent as this).
  • Other values — returned as-is (null, 0, strings, etc.).
javascript
import result from "lodash/result";

const user = {
  name: "John Doe",
  greet() {
    return `Hello, my name is ${this.name}.`;
  }
};

const userName = result(user, "name");
const greeting = result(user, "greet");

// userName -> "John Doe"
// greeting  -> "Hello, my name is John Doe."

⚡ Quick Reference

TaskCode patternResult
Read property_.result(obj, "name")Value at key
Invoke method_.result(obj, "greet")Calls function, returns output
Nested path_.result(obj, "profile.city")Deep read + invoke rules
Missing path_.result(obj, "age", "N/A")Returns default
Lazy default_.result(obj, "theme", () => "light")Runs default fn if undefined
Plain read only_.get(obj, "greet")Use _.get()
Functions
auto-invoke

With parent this

Default when
undefined

Not null/missing fn

Paths
dot or array

Nested access

Pair with
_.get()

Non-invoking read

🧰 Parameters

Arguments to _.result() and how Lodash resolves them:

object Required

The object to query. Lodash walks the path on this object before applying invoke/default logic.

_.result(user, "email", "none")
path Required

Property path: string with dots, array of keys, or a single key. Same path formats as _.get and _.set.

_.result(car, "details.make")
_.result(car, ["details", "make"])
defaultValue Optional

Returned when the resolved value is undefined. Can be a plain value or a function (invoked with parent as this).

_.result(cfg, "theme", "light")
resolution Behavior

If the value at path is a function → call it. If result is undefined → use default. Otherwise return the value.

// null and false are returned as-is

A property that exists but holds a non-function value (like a string) is returned directly—the default is not used unless the resolved value is undefined.

Examples Gallery

Practical _.result() patterns with sample output and interactive Try It Yourself labs.

📚 Getting Started

Read properties and invoke object methods in one call.

Example 1 — Read a property and invoke a method

Get name directly and call greet() with the correct this binding.

javascript
const user = {
  name: "John Doe",
  age: 30,
  greet() {
    return `Hello, my name is ${this.name}.`;
  }
};

const userName = _.result(user, "name");
const userGreeting = _.result(user, "greet");

console.log(userName);
// -> "John Doe"

console.log(userGreeting);
// -> "Hello, my name is John Doe."
Try It Yourself

How It Works

Plain values are returned unchanged. Functions are invoked automatically so you do not write user.greet() yourself.

Example 2 — Default for missing properties

When age is absent, return a friendly fallback string.

javascript
const user = {
  name: "Jane Doe"
};

const userAge = _.result(user, "age", "Age not available");

console.log(userAge);
// -> "Age not available"
Try It Yourself

How It Works

The default applies only when the resolved value is undefined. If age: null existed, null would be returned—not the default.

📈 Practical Patterns

Nested paths, lazy defaults, and configuration objects.

Example 3 — Nested property path

Read deeply nested data with dot notation or an array of keys.

javascript
const car = {
  details: {
    make: "Toyota",
    model: "Camry"
  }
};

const carMake = _.result(car, "details.make");
const carModel = _.result(car, ["details", "model"]);

console.log(carMake, carModel);
// -> "Toyota" "Camry"
Try It Yourself

Example 4 — Lazy default function

Compute an expensive fallback only when the path is missing.

javascript
const config = {
  locale: "en-US"
};

const theme = _.result(config, "theme", function () {
  return this.locale === "en-US" ? "light" : "dark";
});

console.log(theme);
// -> "light" (default fn ran because theme was undefined)

How It Works

When defaultValue is a function and the path resolves to undefined, Lodash calls the default with the parent object as this.

Example 5 — _.result vs _.get

Same path, different behavior when the value is a function.

javascript
const user = {
  name: "Alex",
  greet() {
    return `Hi, ${this.name}!`;
  }
};

_.get(user, "greet");    // -> [Function: greet]
_.result(user, "greet"); // -> "Hi, Alex!"

🚀 Beyond the Basics

Dynamic profile access and API-style defaults.

Example 6 — Safe email with API default

Provide a placeholder when optional user data is missing from a record.

javascript
const user = {
  name: "John Doe"
};

const userEmail = _.result(user, "email", "Email not provided");

console.log(userEmail);
// -> "Email not provided"

🧠 How _.result() Works

1

Resolve path

Lodash walks the object using the path string or key array.

Navigate
2

Invoke if function

If the value at the path is a function, call it with the parent as this.

Execute
3

Apply default

If the final resolved value is undefined, return or invoke defaultValue.

Fallback
=

Value returned

One safe read that handles methods and missing data without extra branching.

📝 Notes

  • Defaults apply only when the resolved value is undefined, not null.
  • A string at the path (e.g. greet: "Hello") is returned as-is—the default is not used.
  • Functions at the path are always invoked; use _.get() if you need the function reference.
  • Methods run with the parent object as this—same as object.method().
  • If a method throws, the error propagates; _.result() does not catch it.
  • For writing nested values, see the next tutorial: _.set().

Conclusion

_.result() combines safe path resolution, automatic method invocation, and optional defaults in one call. Use it when objects expose behavior as functions or when you want readable fallbacks for missing configuration.

For plain reads without invoking functions, use _.get(). To write values at nested paths, continue to _.set().

💡 Best Practices

✅ Do

  • Use _.result() for computed properties stored as methods
  • Pass function defaults when fallback logic is non-trivial
  • Prefer dot paths or arrays consistently across your codebase
  • Use _.get() when you intentionally need a function reference
  • Document which paths may invoke side-effect methods

❌ Don’t

  • Expect defaults when the value is null (use ?? or explicit checks)
  • Assume non-function values trigger the default
  • Call _.result() on paths whose methods have heavy side effects unknowingly
  • Replace _.get() everywhere—only when invoke/default behavior helps
  • Forget that invalid intermediate paths return undefined and then the default

Key Takeaways

Knowledge Unlocked

Five things to remember about _.result()

Use these when reading objects with methods or optional fields.

5
Core concepts
▶️ 02

Invoke fn

Auto-call methods.

Behavior
📝 03

Default

When undefined.

Fallback
🔗 04

this

Parent object.

Binding
📋 05

vs get

No auto-invoke.

Compare

❓ Frequently Asked Questions

_.result() resolves a property path on an object. If the value is a function, it is called with the parent object as this and the return value is used. If the resolved value is undefined, the optional default is returned instead.
_.get() returns whatever sits at the path—including functions without calling them. _.result() automatically invokes functions found at the path and supports default fallbacks when the resolved value is undefined.
Only when the resolved value is undefined—typically because the path is missing or explicitly set to undefined. If the property exists with any other value (including null, false, or a string), that value is returned.
Yes. If the resolved value is undefined and defaultValue is a function, Lodash invokes defaultValue with the parent object as this and returns its result.
Yes. Pass a dot-path string like profile.name or an array of keys like ["profile", "name"]. Lodash walks the object chain before applying the function-or-default rules.
No for reads. If a method at the path mutates the object when invoked, that is the method's behavior—not _.result() itself.
Did you know?

_.result is the read/invoke counterpart to writing with _.set(). Together they cover the two most common nested-object operations in Lodash—plus _.get() when you want the raw value without calling functions.

Practice _.result() in the Live Editor

Run the examples and experiment with paths, methods, and defaults.

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