Underscore.js _.allKeys() Method

Beginner
5 min read
Updated: Nov 2026
4 examples
Object

Definition

Retrieve all the names of an object’s own and inherited properties (official Underscore docs). Stable Object helper — not deprecated.

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

Syntax

Call _.allKeys. Start with this line.

Underscore
_.allKeys(object)
CallWhat it does
_.allKeys(object)Primary signature.
_.allKeys(...)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
_.allKeys(object)

Parameters

ParameterDescription
objectRequired. Value to inspect

Return Value

Return ValueDescription
*New array of enumerable key names

Underscore.js Examples

Example 1 — Official Docs Object

List the enumerable names on a plain object.

Underscore
_.allKeys({ one: 1, two: 2, three: 3 });
// → ["one", "two", "three"]
Try It Yourself

How It Works

  1. Plain object. All three properties are own and enumerable.
  2. Collect. Underscore builds an array of their names.
  3. Same as keys here. No prototype extras → matches _.keys.
  4. Docs sample. This is the official Underscore example.

Example 2 — Own vs Inherited (_.keys)

See the difference when a property lives on the prototype.

Underscore
function Base() { this.own = 1; }
Base.prototype.shared = 2;

var obj = new Base();

_.keys(obj);      // → ["own"]
_.allKeys(obj);   // → ["own", "shared"]
Try It Yourself

How It Works

  1. Own. own sits on the instance.
  2. Inherited. shared sits on Base.prototype.
  3. keys. Sees only the instance field.
  4. allKeys. Walks the chain and keeps both enumerable names.

Example 3 — Object.create Prototype

Inherited keys also appear when you set a prototype with Object.create.

Underscore
var proto = { role: "admin" };
var user = Object.create(proto);
user.name = "Ada";

_.keys(user);       // → ["name"]
_.allKeys(user);    // → ["name", "role"]
Try It Yourself

How It Works

  1. Create. user inherits from proto.
  2. Own field. name is set on user.
  3. Inherited. role comes from the prototype object.
  4. allKeys. Lists both enumerable names.

Example 4 — Empty Object, Null & Primitives

Safe on empty objects and non-objects — always an array.

Underscore
_.allKeys({});           // → []
_.allKeys(null);         // → []
_.allKeys(42);           // → []
_.allKeys("hi");         // → []  (primitive string)
Try It Yourself

How It Works

  1. Empty object. No enumerable names → [].
  2. null. Not an object to walk → [].
  3. Primitives. Underscore returns [] instead of throwing.
  4. Safe default. Easy to call without extra type guards.

Browser & Runtime Support

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

_.allKeys()

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

_.allKeys(object) returns an array of the object’s enumerable property names, including ones inherited through the prototype chain. Official plain-object sample: _.allKeys({one:1, two:2, three:3}) → ["one","two","three"].
_.keys lists only own enumerable properties. _.allKeys also includes enumerable inherited properties from the prototype chain.
No. Only enumerable names are listed — same rule as _.keys — but allKeys also walks prototypes.
_.allKeys returns [] for null, undefined, and primitives instead of throwing.
When inspecting constructor instances and you care about inherited defaults or methods. For plain data objects, _.keys is usually enough.
Order follows the engine’s enumeration (often own keys before inherited). Do not rely on a specific order for correctness.

Next: _.values()

Get an array of an object’s own enumerable values.

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