Lodash _.keysIn() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Object

Definition

Creates an array of the own and inherited enumerable property names of object. Part of Lodash Object since 3.0.0 (stable — not deprecated). Non-object values are coerced to objects.

Note: Official docs say iteration order is not guaranteed. Only enumerable inherited keys appear — ES class methods usually do not.

Syntax

Call _.keysIn. Start with this line.

Lodash
_.keysIn(object)
CallWhat it does
_.keysIn(object)Primary signature.

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

Library declarations
Lodash
_.keysIn(object)

Parameters

ParameterDescription
objectRequired. Object to query (non-objects are coerced)

Return Value

Return ValueDescription
*Array of own + inherited enumerable names

Lodash Examples

Example 1 — Official: Own + Inherited

Prototype properties that are enumerable are included.

Lodash
function Foo() {
  this.a = 1;
  this.b = 2;
}

Foo.prototype.c = 3;

_.keysIn(new Foo);
// → ['a', 'b', 'c']  (order not guaranteed)
Try It Yourself

How It Works

  1. Own. Instance sets a and b.
  2. Inherited. Foo.prototype.c is enumerable.
  3. keysIn. Collects both layers → a, b, c.
  4. Order. Docs do not guarantee iteration order.

Example 2 — keysIn vs keys

Same object; only keysIn keeps the prototype key.

Lodash
function Foo() {
  this.a = 1;
  this.b = 2;
}
Foo.prototype.c = 3;

_.keysIn(new Foo);  // → ['a', 'b', 'c']
_.keys(new Foo);    // → ['a', 'b']
Try It Yourself

How It Works

  1. keysIn. Walks the prototype chain.
  2. keys. Stops at own properties.
  3. Diff. Inherited c is the difference.
  4. Pick. Use own-only when prototypes should stay hidden.

Example 3 — Plain Object

With no custom prototype keys, keysIn matches keys.

Lodash
_.keysIn({ x: 1, y: 2 });
// → ['x', 'y']
Try It Yourself

How It Works

  1. Literal. Own keys x and y.
  2. Prototype. Object.prototype has no enumerable keys for this case.
  3. Result. Same list you would get from _.keys.
  4. Use. Safe default for plain data objects.

Example 4 — Null & Undefined

Nullish values return an empty array instead of throwing.

Lodash
_.keysIn(null);
// → []

_.keysIn(undefined);
// → []
Try It Yourself

How It Works

  1. Coerce. Lodash treats nullish as empty objects for this helper.
  2. No keys. Nothing to collect.
  3. Result. [] for both.
  4. Safer. Unlike native Object.keys(null), which throws.

Example 5 — String Coercion

Strings become objects with index keys.

Lodash
_.keysIn('hi');
// → ['0', '1']
Try It Yourself

How It Works

  1. Coerce. 'hi' becomes a String object.
  2. Indexes. Characters live at keys '0' and '1'.
  3. Result. Those indexes are enumerable → returned.
  4. Same idea. Matches how _.keys('hi') behaves for own indexes.

Browser & Runtime Support

_.keysIn is a Lodash Object helper since 3.0.0. It runs anywhere Lodash runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install lodash.

✓ Stable · Lodash 3.0.0+

_.keysIn()

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

100% With Lodash 3+
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
_.keysIn Lodash 3.0.0+

Bottom line: Safe for production once Lodash is loaded. Prefer import keysIn from "lodash/keysIn" for smaller bundles. Use it when inherited enumerable keys must be visible.

Frequently Asked Questions

_.keysIn(object) creates an array of the own and inherited enumerable property names of object. Official: _.keysIn(new Foo) → ['a', 'b', 'c'] when Foo.prototype.c is enumerable.
_.keys returns only own enumerable string keys. _.keysIn also includes inherited enumerable string keys from the prototype chain.
Usually no. Class methods on the prototype are non-enumerable. Older Foo.prototype.method = fn assignments are enumerable by default, so those do appear.
No. It returns string-keyed property names only.
Yes. _.keysIn(null) and _.keysIn(undefined) return [] instead of throwing.
Use import keysIn from "lodash/keysIn" or require("lodash/keysIn") for tree-shaking. Full build: import _ from "lodash" then _.keysIn.

Next: _.mapKeys()

Create an object with keys mapped by a function.

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