Lodash _.toPairsIn() Method

Beginner
⏱️ 7 min read
📚 Updated: Jul 2026
🎯 6 Examples + 3 Try It
Object utilities

What You’ll Learn

By the end of this tutorial, you’ll use _.toPairsIn() to list own and inherited enumerable keys as [key, value] pairs.

01

Core syntax

_.toPairsIn(object) returns tuple array.

02

Inherited keys

Includes prototype enumerable properties.

03

vs toPairs

Own-only vs full chain.

04

Non-mutating

Returns a new array.

05

Inspection

Debug class instances and prototypes.

06

When to skip

Prefer _.toPairs() for plain data.

What Is _.toPairsIn()?

_.toPairsIn() is like _.toPairs(), but it walks the prototype chain and includes inherited enumerable string-keyed properties too. Think of it as turning a for...in loop into an array of [key, value] tuples.

💡
Own vs inherited

On a class instance, _.toPairs() might return only name, while _.toPairsIn() also lists prototype methods like speak if they are enumerable.

Use it for object inspection, debugging prototype-augmented instances, and understanding what enumerable keys exist beyond own properties. For API payloads and plain config objects, _.toPairs() is usually the safer default.

📝 Syntax

The signature takes one argument—the object to convert:

javascript
_.toPairsIn(object)

Syntax Rules

  • object — the object to convert (instances, plain objects, etc.).
  • Return value — array of [key, value] tuples.
  • Included keys — own and inherited enumerable string-keyed properties.
  • Excluded — non-enumerable keys and symbol keys (same rules as for...in).
  • Nested values — not flattened; nested objects stay in the value slot.
javascript
import toPairsIn from "lodash/toPairsIn";

function Animal(name) {
  this.name = name;
}
Animal.prototype.speak = function () {
  console.log(this.name + " makes a sound.");
};

const dog = new Animal("Dog");
const pairs = toPairsIn(dog);

// pairs includes own "name" and inherited "speak"

⚡ Quick Reference

TaskCode patternResult
Instance + prototype_.toPairsIn(dog)Own + inherited enumerable
Own keys only_.toPairs(obj)Use _.toPairs()
Object.create chain_.toPairsIn(child)Parent props included
Iterate all pairs_.toPairsIn(o).forEach(...)Array iteration
Plain data object_.toPairs(obj)Usually enough
Key names only_.keysIn(obj)See _.keysIn()
Scope
Inherited

+ own enumerable

Mutates?
No

New array

Like
for...in

As pairs

Default
toPairs

Plain data

🧰 Parameters

The single argument to _.toPairsIn() and what comes back:

object Required

Any object whose own and inherited enumerable string-keyed properties become pairs.

_.toPairsIn(instance)
return value Output

Array of [key, value] tuples from the prototype chain walk.

[["name", "Dog"], ["speak", fn]]
inherited keys Scope

Enumerable properties on prototypes are included—the main difference from _.toPairs.

Object.create(parent, { ... })
non-enumerable Excluded

Non-enumerable prototype methods (common in modern classes) do not appear in the result.

class methods often skipped

On a plain object literal with no prototype extras, _.toPairsIn and _.toPairs return the same pairs.

Examples Gallery

Practical _.toPairsIn() patterns with sample output and interactive Try It Yourself labs.

📚 Getting Started

See inherited enumerable properties appear as pairs.

Example 1 — Constructor instance with prototype method

Include own name and inherited enumerable speak from the prototype.

javascript
function Animal(name) {
  this.name = name;
}
Animal.prototype.speak = function () {
  console.log(this.name + " makes a sound.");
};

const dog = new Animal("Dog");
const animalPairs = _.toPairsIn(dog);

console.log(animalPairs.map(function (p) { return p[0]; }));
// -> ["name", "speak"]
Try It Yourself

How It Works

_.toPairs() would return only [["name", "Dog"]]; _.toPairsIn walks the prototype too.

Example 2 — Object.create parent chain

Child own property plus inherited parentProp from the parent object.

javascript
const parentObject = { parentProp: "parentValue" };
const childObject = Object.create(parentObject, {
  childProp: { value: "childValue", enumerable: true }
});

const childPairs = _.toPairsIn(childObject);

console.log(childPairs);
// -> [["childProp", "childValue"], ["parentProp", "parentValue"]]
Try It Yourself

📈 Practical Patterns

Compare with toPairs, iterate entries, and inspect plain objects.

Example 3 — _.toPairsIn() vs _.toPairs()

Same count on plain literals; different on prototype-augmented instances.

javascript
function Greeter(msg) { this.msg = msg; }
Greeter.prototype.greet = function () { return this.msg; };

const g = new Greeter("Hi");

console.log(_.toPairs(g).length);    // -> 1 (own only)
console.log(_.toPairsIn(g).length);  // -> 2 (own + greet)
Try It Yourself

Example 4 — Iterate all enumerable keys

Log every own and inherited enumerable property on an instance.

javascript
function Vehicle(type) { this.type = type; }
Vehicle.prototype.honk = function () { return "beep"; };

const car = new Vehicle("car");

_.toPairsIn(car).forEach(function (pair) {
  console.log(pair[0] + ": " + typeof pair[1]);
});
// type: string
// honk: function

Example 5 — Plain object (same as toPairs)

On a simple literal with no extra prototype keys, both methods match.

javascript
const plain = { a: 1, b: 2, c: 3 };

console.log(
  JSON.stringify(_.toPairs(plain)) === JSON.stringify(_.toPairsIn(plain))
);
// -> true

🚀 Beyond the Basics

Related key-enumeration helpers in Lodash.

Example 6 — Pair with _.keysIn()

_.keysIn() returns only key names; _.toPairsIn returns keys with values.

javascript
function Tool(name) { this.name = name; }
Tool.prototype.use = function () { return "used"; };

const hammer = new Tool("hammer");

console.log(_.keysIn(hammer));
// -> ["name", "use"]

console.log(_.toPairsIn(hammer)[1]);
// -> ["use", function use() { ... }]

🧠 How _.toPairsIn() Works

1

Walk prototype chain

Lodash enumerates enumerable string keys like a for...in loop.

Input
2

Collect key + value

Each enumerable key becomes a [key, value] tuple in a new array.

Pair
3

Return array

The source object is not modified; you get a fresh pairs array.

Output
=

Full enumerable view

Own and inherited enumerable properties are visible as iterable pairs.

📝 Notes

  • _.toPairsIn() includes inherited enumerable properties—not just own keys.
  • On plain object literals, results usually match _.toPairs().
  • Non-enumerable prototype methods (common in ES6 classes) are excluded.
  • Nested object values are not flattened into additional pairs.
  • There is no built-in Object.entriesIn—that is why _.toPairsIn exists.
  • For API payloads and config objects, prefer _.toPairs() to avoid prototype noise.

Conclusion

_.toPairsIn() exposes own and inherited enumerable properties as iterable [key, value] pairs—ideal for debugging instances and prototype chains. For everyday data objects, _.toPairs() is the safer default.

Pair it with _.keysIn() when you only need names, or continue to _.transform() for accumulator-style object reduction.

💡 Best Practices

✅ Do

  • Use _.toPairsIn to inspect instances with prototype methods
  • Prefer _.toPairs for JSON-like data and API responses
  • Check whether inherited keys are enumerable before expecting them in output
  • Destructure tuples as [key, value] in array callbacks
  • Compare pair counts with _.toPairs to spot prototype extras

❌ Don’t

  • Assume _.toPairsIn recurses into nested object values
  • Expect circular reference values to cause infinite loops—enumeration is shallow
  • Use Object.entries as a drop-in for inherited keys (it is own-only)
  • Serialize instances with inherited functions unless you mean to
  • Confuse toPairsIn with deep flattening utilities

Key Takeaways

Knowledge Unlocked

Five things to remember about _.toPairsIn()

Use these when inherited enumerable keys matter.

5
Core concepts
🔗 02

[key, value]

Tuple array.

Output
🔀 03

vs toPairs

Own-only sibling.

Compare
🛠️ 04

Inspection

Debug prototypes.

Use case
📦 05

Non-mutating

New array.

Note

❓ Frequently Asked Questions

_.toPairsIn() converts an object into an array of [key, value] pairs, including own and inherited enumerable string-keyed properties on the prototype chain.
_.toPairs() includes only own enumerable properties. _.toPairsIn() also includes inherited enumerable properties from prototypes—like a for...in loop turned into pairs.
No. It reads the object and returns a new array. The source object is unchanged.
There is no single Object.entries variant for inherited keys. You typically use a for...in loop or combine manual prototype walking. _.toPairsIn() packages that pattern.
No. Like _.toPairs(), it only enumerates top-level keys on the object and its prototype chain. Nested object values stay as values inside each pair.
Use _.toPairs() for plain data objects, API payloads, and config where inherited prototype methods should not appear. Use _.toPairsIn() for debugging or inspecting prototype-augmented instances.
Did you know?

Some tutorials claim _.toPairsIn() hits infinite loops on circular references—that is misleading. Enumeration is shallow: a circular value may appear as a pair’s value, but Lodash does not recursively walk into nested objects. Also, Object.entries() is not equivalent to _.toPairsIn() for inherited keys.

Practice _.toPairsIn() in the Live Editor

Inspect prototype chains, compare with toPairs, and iterate inherited keys instantly.

Open Try It editor →

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.

6 people found this page helpful