Lodash _.has() method

Beginner
⏱️ 7 min read
📚 Updated: May 2026
🎯 3 Code examples
🚀 3 Try-it labs
Lodash

What you’ll learn

  • How _.has(object, path) checks whether an own property exists at a nested path.
  • Why existing falsey values still return true.
  • How string paths, bracket notation, and array paths behave.
  • When to use _.hasIn(), _.get(), or native Object.hasOwn() instead.

Prerequisites

You should know the difference between reading a value and checking whether a property exists. _.has answers existence, not truthiness.

  • Own properties only: inherited prototype properties return false with _.has.
  • Falsey values still exist: null, undefined, 0, false, and "" all count if the property is present.
  • Path syntax matters: use array paths for keys that literally contain dots or brackets.

Overview

_.has walks a path and returns true when every segment exists as an own property on the current object. It is useful when you need to distinguish "this property is present with a falsey value" from "this property is missing entirely".

Existence, not value

A present property whose value is undefined still returns true.

Own properties only

Prototype properties do not count. Use _.hasIn when they should.

Nested path support

Use dotted strings, bracket strings, or arrays for deeply nested checks.

Syntax

javascript
_.has(object, path)
  • object: the object to inspect. null or undefined returns false.
  • path: a string path ("a.b[0]") or array path (["a", "b", 0]).
  • Returns: true if the full path exists as own properties; otherwise false.
1

Check a nested own property

Use _.has when you need a boolean before deciding whether to read or render a nested value.

javascript
import has from "lodash/has";

const sample = {
  user: {
    name: "John Doe",
    address: {
      city: "Exampleville",
      postalCode: "12345"
    }
  },
  isActive: true
};

has(sample, "user.address.postalCode");
// -> true

has(sample, "user.address.country");
// -> false

has(sample, "isActive");
// -> true
Try it Yourself
2

Falsey values still count as existing

_.has is not a truthiness test. It returns true when the property is present, even if the stored value is falsey.

javascript
import has from "lodash/has";

const settings = {
  theme: null,
  retries: 0,
  enabled: false,
  label: "",
  explicit: undefined
};

has(settings, "theme");    // -> true
has(settings, "retries");  // -> true
has(settings, "enabled");  // -> true
has(settings, "label");    // -> true
has(settings, "explicit"); // -> true
has(settings, "missing");  // -> false
Try it Yourself
3

Array paths and inherited properties

Array paths preserve literal keys and avoid ambiguity. Inherited properties are deliberately excluded by _.has.

javascript
import has from "lodash/has";
import hasIn from "lodash/hasIn";

const proto = { inheritedFlag: true };
const record = Object.create(proto);
record.items = [{ id: 1 }];
record["x.y"] = { z: 42 };

has(record, "items[0].id");
// -> true

has(record, ["x.y", "z"]);
// -> true

has(record, "x.y.z");
// -> false  (looks for record.x.y.z)

has(record, "inheritedFlag");
// -> false

hasIn(record, "inheritedFlag");
// -> true
Try it Yourself

📋 _.has vs related checks

Topic_.has_.hasIn_.getObject.hasOwn()
Nested path supportYesYesYesNo
Own propertiesYesYesReads themYes
Inherited propertiesNoYesReads themNo
Returns valueNo, booleanNo, booleanYesNo, boolean
Falsey valuesStill true if presentStill true if presentReturns the valueStill true if present

Use _.has for nested own-property checks, _.hasIn for own-or-inherited checks, _.get when you need the value, and Object.hasOwn() for one-level native checks.

Pitfalls to avoid

Truthiness

Do not treat _.has like an if (value) check

A property containing false, 0, or null can still be a valid, intentional value.

Prototype

Inherited properties return false

This is by design. Use _.hasIn only when inherited properties are part of the expected API.

Dots in keys

Dotted keys need array paths

"x.y.z" means three segments. Use ["x.y", "z"] if "x.y" is one literal key.

Untrusted input

Validate dynamic paths

If a path comes from a request or query string, compare it against an allow-list before checking internal object shapes.

❓ FAQ

It checks whether an object has an own property at the given path. The path can be a string like 'a.b[0]' or an array like ['a', 'b', 0].
No. _.has only checks own properties. Use _.hasIn when inherited properties from the prototype chain should count.
No. Existence is not truthiness. If the property exists with undefined, null, false, 0, or an empty string, _.has returns true.
_.has answers whether an own property path exists. _.get reads the value at a path and can return a default when the resolved value is undefined.
It accepts dotted strings, bracket notation strings, and array paths. Use array paths when a key literally contains dots or square brackets.
Yes. Numeric path segments check indexes. Existing indexes return true, but sparse array holes return false because the index is not an own property.

Summary

Did you know?

_.has checks whether the path exists as an own property. It returns true even when the value is undefined, null, false, 0, or an empty string.

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.

5 people found this page helpful