Lodash _.has() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Object

Definition

Checks if path is a direct (own) property of object. Part of Lodash Object (stable — not deprecated). Nested paths work with dotted strings or path arrays. Inherited prototype properties return false — use _.hasIn for those.

Pass the object and path or keys shown below. Check whether the helper mutates or returns a new object.

Syntax

Call _.has. Start with this line.

Lodash
_.has(object, path)
CallWhat it does
_.has(object, path)Primary signature.
_.has(object)Work with an object’s keys, values, or paths.

Prefer import has from "lodash/has" when you want a smaller bundle.

Library declarations
Lodash
_.has(object, path)

Parameters

ParameterDescription
objectRequired. Object to query
pathRequired. String or array path to check

Return Value

Return ValueDescription
*true if path exists as own property

Lodash Examples

Example 1 — Official: Own Top-Level Key

A direct own property returns true.

Lodash
var object = { a: { b: 2 } };

console.log(_.has(object, "a")); // true
Try It Yourself

How It Works

  1. Object. Has its own key a.
  2. Path. Simple string 'a'.
  3. Result. true — matches the official docs.
  4. Tip. This does not read the value — only existence.

Example 2 — Official: Nested String & Array Paths

Both path styles resolve the same own chain.

Lodash
var object = { a: { b: 2 } };

console.log(_.has(object, "a.b"));     // true
console.log(_.has(object, ["a", "b"])); // true
console.log(_.has(object, "a.c"));     // false
Try It Yourself

How It Works

  1. String path. 'a.b' walks own keys a then b.
  2. Array path. ['a', 'b'] does the same walk.
  3. Missing. 'a.c' fails at segment c.
  4. Docs. Matches the official nested examples.

Example 3 — Official: Inherited Path Is False

Prototype properties are not “direct.”

Lodash
var other = _.create({ a: _.create({ b: 2 }) });

console.log(_.has(other, "a"));   // false
console.log(other.a);             // { b: 2 }  (via prototype)
Try It Yourself

How It Works

  1. create. other inherits a — it is not own.
  2. has. Own-property check → false.
  3. Access. Reading other.a still works via the prototype.
  4. Docs. Matches the official other example.

Example 4 — Falsy Values Still Exist

Existence is not the same as truthiness.

Lodash
var data = { count: 0, note: "", flag: false, empty: null };

console.log(_.has(data, "count")); // true
console.log(_.has(data, "note"));  // true
console.log(_.has(data, "flag"));  // true
console.log(_.has(data, "empty")); // true
console.log(Boolean(data.count));  // false
Try It Yourself

How It Works

  1. Keys exist. Each property is an own key.
  2. has. Returns true for all of them.
  3. Truthiness. Boolean(0) is still false.
  4. Rule. Use has for presence; use the value for truth checks.

Example 5 — _.has vs _.hasIn

Choose own-only vs own-or-inherited.

Lodash
var other = _.create({ a: _.create({ b: 2 }) });

console.log(_.has(other, "a"));   // false
console.log(_.hasIn(other, "a")); // true
Try It Yourself

How It Works

  1. has. Requires a direct own property → false.
  2. hasIn. Walks the prototype chain → true.
  3. When. Prefer has for “did this object define it?”
  4. When. Prefer hasIn for “can I read it somehow?”

Browser & Runtime Support

_.has is a Lodash Object helper available in 4.x (and earlier builds). It runs anywhere Lodash runs — modern browsers (via CDN or bundle) and Node.js / Bun / Deno with npm install lodash. Native Object.prototype.hasOwnProperty.call(obj, key) covers a single own key; Lodash adds nested path support.

✓ Stable · Lodash 4.x

_.has()

Available in [email protected] full builds and the lodash/has modular import. Works in evergreen browsers and current Node LTS when Lodash is installed.

100% With Lodash 4.x
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
_.has Lodash 4.x

Bottom line: Safe for production once Lodash is on the page or in your bundle. Prefer import has from "lodash/has" for smaller builds. Remember: own properties only.

Frequently Asked Questions

_.has(object, path) checks if path is a direct (own) property of object. Official: _.has({ a: { b: 2 } }, 'a.b') → true.
No. Only own properties count. Use _.hasIn when prototype-chain properties should count too.
No. Existence is not truthiness. A property set to undefined, null, false, 0, or '' still returns true.
Dotted strings like 'a.b', bracket strings, or array paths like ['a', 'b']. Prefer arrays when a key literally contains dots.
_.has answers whether an own path exists. _.get reads the value and can supply a default when the result is undefined.
Use import has from "lodash/has" or require("lodash/has") so bundlers can tree-shake. Full build: import _ from "lodash" then _.has.

Next: _.hasIn()

Check whether a path exists on the object or its prototype chain.

_.hasIn() tutorial →

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.

10 people found this page helpful