Underscore.js _.get() Method

Beginner
5 min read
Updated: Nov 2026
4 examples
Object

Definition

Returns the specified property of object. path may be a simple key or an array of keys/indexes for deep fetching. If the property does not exist or is undefined, the optional default is returned (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 _.get. Start with this line.

Underscore
_.get(object, path, [default])
CallWhat it does
_.get(object, path, [default])Primary signature.
_.get(...)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
_.get(object, path, [default])

Parameters

ParameterDescription
objectRequired. Source to read from
pathRequired. String key or array of keys/indexes
defaultOptional. Returned when value is undefined

Return Value

Return ValueDescription
*Resolved value, or default / undefined

Underscore.js Examples

Example 1 — Official: Simple Key

Pass a string to read one property.

Underscore
_.get({ a: 10 }, "a");
// → 10
Try It Yourself

How It Works

  1. Path. "a" is a single key name.
  2. Lookup. Reads object.a.
  3. Result. Returns 10.
  4. Missing. Without a default, a missing key yields undefined.

Example 2 — Official: Deep Path Array

Use an array of keys and indexes for nested reads.

Underscore
_.get({ a: [{ b: 2 }] }, ["a", 0, "b"]);
// → 2
Try It Yourself

How It Works

  1. Array path. Each element is one step into the structure.
  2. "a". Selects the nested array.
  3. 0. Selects the first object in that array.
  4. "b". Reads the final value 2.

Example 3 — Official: Default Value

When the path resolves to undefined, return your fallback.

Underscore
_.get({ a: 10 }, "b", 100);
// → 100

_.get({ a: null }, "a", 100);
// → null   // null is not undefined
Try It Yourself

How It Works

  1. Missing key. "b" is undefined → default 100.
  2. null present. a is null — returned unchanged.
  3. Rule. Default fires only for undefined.
  4. Falsy OK. 0, false, and "" also keep their values.

Example 4 — Safe Nested Read

Middle null/undefined does not throw — unlike chained brackets.

Underscore
var user = { profile: null };

_.get(user, ["profile", "name"], "guest");
// → "guest"

// user.profile.name  → TypeError
Try It Yourself

How It Works

  1. Step 1. profile is null.
  2. Stop. Cannot continue to name — no throw.
  3. Default. Returns "guest".
  4. vs brackets. user.profile.name would throw a TypeError.

Browser & Runtime Support

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

_.get()

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

Frequently Asked Questions

_.get(object, path, [default]) reads a property by a simple key or a deep path (array of keys/indexes). If the value is missing or undefined, it returns the optional default.
Pass an array of keys and indexes — e.g. _.get(obj, ['a', 0, 'b']). Prefer arrays for deep access; a single string is one key name.
When the resolved value is undefined (missing path or an explicit undefined). null, 0, false, and '' are returned as-is — they do not trigger the default.
No. It safely stops and returns the default (or undefined) instead of throwing like obj.a.b on a null a.
_.property(path) returns a function you can reuse. _.get(object, path) reads once from a given object.
No. It only reads values.

Next: _.property()

Turn a path into a reusable function for maps and filters.

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