Underscore.js _.has() Method

Beginner
5 min read
Updated: Nov 2026
4 examples
Object

Definition

Does the object contain the given key? Identical to object.hasOwnProperty(key), but uses a safe reference to hasOwnProperty in case it has been overridden (official Underscore docs).

Pass the required arguments shown below. Underscore object helpers usually return a new value — check whether the source object is mutated.

Syntax

Call _.has. Start with this line.

Underscore
_.has(object, key)
CallWhat it does
_.has(object, key)Primary signature.
_.has(...)Call with the arguments your case needs.

Load Underscore with import _ from "underscore" (or the UMD CDN build) so these helpers are available as _.

Library declarations
Underscore
_.has(object, key)

Parameters

ParameterDescription
objectRequired. Object to inspect
keyRequired. Property name to check (single key)

Return Value

Return ValueDescription
*true or false

Underscore.js Examples

Example 1 — Official: Own Key Check

Return true when the key is defined on the object itself.

Underscore
_.has({ a: 1, b: 2, c: 3 }, "b");
// → true

_.has({ a: 1, b: 2, c: 3 }, "z");
// → false
Try It Yourself

How It Works

  1. "b". Present as an own property → true.
  2. "z". Not on the object → false.
  3. Safe. Uses Underscore’s internal hasOwnProperty call.
  4. Single key. Not a deep path API.

Example 2 — Own vs Inherited (in)

in sees prototype keys; _.has does not.

Underscore
var obj = { a: 1 };

"toString" in obj;
// → true

_.has(obj, "toString");
// → false
Try It Yourself

How It Works

  1. in. Walks the prototype chain — finds toString.
  2. has. Only own properties — toString is not own.
  3. Intent. Use _.has when you mean “did I set this key?”
  4. a. _.has(obj, "a") would still be true.

Example 3 — Key Exists with Falsy Value

Existence is not the same as a truthy value.

Underscore
var flags = { ready: false, count: 0 };

_.has(flags, "ready");
// → true

_.has(flags, "count");
// → true

!!flags.ready;
// → false
Try It Yourself

How It Works

  1. Keys present. Both ready and count are own keys.
  2. has → true. Values do not matter for the check.
  3. Truthiness. !!flags.ready is about the value, not the key.
  4. undefined key. A missing key would still be false from _.has.

Example 4 — Safe with Object.create(null)

Works when there is no Object.prototype (and no hasOwnProperty method).

Underscore
var dict = Object.create(null);
dict.token = "abc";

_.has(dict, "token");
// → true

// dict.hasOwnProperty("token") → TypeError
Try It Yourself

How It Works

  1. Null prototype. dict has no inherited methods.
  2. Direct call fails. dict.hasOwnProperty is undefined.
  3. _.has. Calls hasOwnProperty via a safe reference.
  4. Result. Correctly reports token as own.

Browser & Runtime Support

_.has ships with Underscore.js (1.x). It runs anywhere Underscore runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install underscore.

✓ Stable · Underscore 1.x

_.has()

Available in [email protected] (UMD / ESM). Works in evergreen browsers and current Node LTS when Underscore is loaded.

100% With Underscore 1.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 Underscore 1.x+

Bottom line: Safe for production once Underscore is on the page or in your bundle. Not a native browser API — load Underscore first. Prefer a pinned CDN version (e.g. [email protected]). Modern engines also offer Object.hasOwn for own-key checks.

Frequently Asked Questions

_.has(object, key) returns true if the object has that key as its own property. It is a safe wrapper around hasOwnProperty.
in is true for inherited properties too (like toString). _.has only checks own properties — inherited keys return false.
_.has uses a safe internal hasOwnProperty reference, so it still works if the object overrides hasOwnProperty or was created with Object.create(null).
No. It only checks that the own key exists. The value may be undefined, null, 0, or false and _.has still returns true.
No. Underscore’s _.has takes a single key. For nested reads use _.get. (Lodash’s _.has is different and supports paths.)
No. It only reads whether the key is an own property.

Next: _.get()

Read nested values safely with an optional default.

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