_.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.
Foundation
📝 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"
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.
Important
📝 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.
Wrap Up
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.
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
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about _.toPairsIn()
Use these when inherited enumerable keys matter.
5
Core concepts
🔍01
Inherited
+ own keys.
Core
🔗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.