Lodash _.toPairsIn() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Object

Definition

Creates an array of own and inherited enumerable string-keyed [key, value] pairs for object. Part of Lodash 4.x Object (since 4.0.0).

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

Syntax

Call _.toPairsIn. Start with this line.

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

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

Library declarations
Lodash
_.toPairsIn(object)

Parameters

ParameterDescription
objectRequired. Source whose own + inherited enumerable keys become pairs

Return Value

Return ValueDescription
*Array of [key, value] tuples

Lodash Examples

Example 1 — Official: Instance + Prototype

Inherited enumerable keys appear in the pair list.

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

_.toPairsIn(new Foo());
// → [["a", 1], ["b", 2], ["c", 3]]
// (exact order is not guaranteed)
Try It Yourself

How It Works

  1. Own. a and b live on the instance.
  2. Proto. c is enumerable on Foo.prototype.
  3. Walk. toPairsIn includes both layers.
  4. Docs. Matches the official Lodash example.

Example 2 — Plain Object (Same as toPairs)

With no interesting prototype keys, results match toPairs.

Lodash
_.toPairsIn({ a: 1, b: 2 });
// → [["a", 1], ["b", 2]]
Try It Yourself

How It Works

  1. Literals. Plain objects inherit from Object.prototype.
  2. Methods. Built-ins like toString are usually non-enumerable.
  3. Result. Only a and b show up.
  4. Tip. For data bags, toPairs is enough.

Example 3 — toPairsIn vs toPairs

Side by side: inherited keys are the whole difference.

Lodash
function Proto() {}
Proto.prototype.shared = 9;

var obj = Object.create(Proto.prototype);
obj.own = 1;

_.toPairs(obj);
// → [["own", 1]]

_.toPairsIn(obj);
// → [["own", 1], ["shared", 9]]
Try It Yourself

How It Works

  1. toPairs. Stops at own enumerable keys.
  2. toPairsIn. Continues onto the prototype.
  3. Object.entries. Matches toPairs (own only).
  4. Pick. Data → toPairs. Inspection → toPairsIn.

Example 4 — Non-Enumerable Keys Are Skipped

Only enumerable properties become pairs — even on the prototype.

Lodash
function Box() {
  this.open = true;
}
Object.defineProperty(Box.prototype, "secret", {
  value: 42,
  enumerable: false
});
Box.prototype.visible = "yes";

_.toPairsIn(new Box());
// → includes ["open", true] and ["visible", "yes"]
// → does NOT include "secret"
Try It Yourself

How It Works

  1. Enumerable. visible is enumerable → included.
  2. Hidden. secret is non-enumerable → skipped.
  3. Same rule. Matches for...in visibility.
  4. Debug tip. Use Object.getOwnPropertyNames for non-enumerable own keys.

Example 5 — Nested Values Stay Nested

Like toPairs, this is not a deep flatten.

Lodash
function Bag() {
  this.meta = { tags: ["a"] };
}
Bag.prototype.kind = "bag";

_.toPairsIn(new Bag());
// → [["meta", { tags: ["a"] }], ["kind", "bag"]]
Try It Yourself

How It Works

  1. Top level. Only keys on the object / prototypes.
  2. Value. meta stays an object inside the pair.
  3. Inherited. kind comes from the prototype.
  4. Deep. Recurse yourself if you need nested pairs.

Browser & Runtime Support

_.toPairsIn is a Lodash Object helper (since 4.0.0). It runs anywhere Lodash runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install lodash. Closest native pattern is a for...in loop collecting [key, value] pairs; Object.entries() covers own keys only. Alias: _.entriesIn.

✓ Stable · Lodash 4.x

_.toPairsIn()

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

Bottom line: Safe for production once Lodash is loaded. Prefer import toPairsIn from "lodash/toPairsIn" for smaller builds. Best for prototype inspection — not everyday JSON-shaped data.

Frequently Asked Questions

_.toPairsIn(object) returns [key, value] pairs for own and inherited enumerable string-keyed properties — like for...in turned into pairs.
toPairs is own keys only. toPairsIn also walks the prototype chain for inherited enumerable keys.
Object.entries() is own-only. There is no built-in entriesIn — you would write a for...in loop yourself.
No. It returns a new array. The source object is unchanged.
No. Nested values stay nested inside each pair’s value slot.
Use import toPairsIn from "lodash/toPairsIn" or require("lodash/toPairsIn"). Full build: _.toPairsIn. Alias: _.entriesIn.

Next: _.transform()

Build a new object or array with an accumulator iteratee.

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