Lodash _.hasIn() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Object

Definition

Checks if path is a direct or inherited property of object. Part of Lodash Object (stable — not deprecated). Like a normal property lookup: prototype-chain keys count. For own-only checks, use _.has.

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

Syntax

Call _.hasIn. Start with this line.

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

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

Library declarations
Lodash
_.hasIn(object, path)

Parameters

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

Return Value

Return ValueDescription
*true if path exists (own or inherited)

Lodash Examples

Example 1 — Official: Inherited Top-Level Key

Prototype properties count for hasIn.

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

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

How It Works

  1. create. object inherits a — it is not own.
  2. hasIn. Prototype lookup finds a → true.
  3. Contrast. _.has(object, 'a') would be false.
  4. Docs. Matches the official first example.

Example 2 — Official: Nested String & Array Paths

Inherited nested chains work with both path styles.

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

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

How It Works

  1. Walk. Resolve inherited a, then inherited b.
  2. String. 'a.b' → true.
  3. Array. ['a', 'b'] → same result.
  4. Docs. Matches the official nested examples.

Example 3 — Official: Missing Path

A path that never exists still returns false.

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

console.log(_.hasIn(object, "b")); // false
Try It Yourself

How It Works

  1. Look. There is no top-level b on the object or prototypes.
  2. Note. Nested a.b exists — bare b does not.
  3. Result. false — matches the official docs.
  4. Tip. Path segments are absolute from the root object.

Example 4 — _.has vs _.hasIn

Same inherited object, different answers.

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

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

How It Works

  1. has. Own-only → false for inherited a.
  2. hasIn. Prototype walk → true.
  3. When. Prefer has for “did this object define it?”
  4. When. Prefer hasIn for “can I read it somehow?”

Example 5 — Own Properties Also Pass

hasIn is a superset — own keys still work.

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

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

How It Works

  1. Own chain. a and b are direct properties.
  2. Both APIs. hasIn and has return true.
  3. Difference. Appears only when inheritance is involved.
  4. Rule. Start with has; switch to hasIn when prototypes matter.

Browser & Runtime Support

_.hasIn 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 key in object covers a single key including inheritance; Lodash adds nested path support.

✓ Stable · Lodash 4.x

_.hasIn()

Available in [email protected] full builds and the lodash/hasIn 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
_.hasIn Lodash 4.x

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

Frequently Asked Questions

_.hasIn(object, path) checks if path is a direct or inherited property of object. Official: with _.create, _.hasIn(object, 'a.b') → true even though the path is inherited.
_.has only counts own properties. _.hasIn also counts properties found on the prototype chain.
No. Existence is not truthiness. A path whose value is undefined, null, false, 0, or '' still returns true.
Dotted strings like 'a.b' or array paths like ['a', 'b']. Prefer arrays when a key literally contains dots.
Yes. Methods live on the prototype, so _.hasIn(instance, 'methodName') is typically true while _.has is false.
Use import hasIn from "lodash/hasIn" or require("lodash/hasIn") so bundlers can tree-shake. Full build: import _ from "lodash" then _.hasIn.

Next: _.invert()

Create an object with keys and values swapped.

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