_.toPairs() converts a plain object into an array of two-element arrays— each inner array is a [key, value] tuple. It is Lodash’s version of Object.entries() and is the object-side counterpart to _.fromPairs(), which does the reverse.
💡
Arrays make iteration simple
Once you have pairs, you can use familiar array methods—map, filter, reduce—instead of manual for...in loops.
Use it when building forms from object data, transforming keys, serializing for APIs, or piping object data through Lodash chains before converting back with _.fromPairs().
Foundation
📝 Syntax
The signature takes one argument—the object to convert:
javascript
_.toPairs(object)
Syntax Rules
object — any object (or object-like value Lodash accepts).
Return value — array of [key, value] tuples.
Included keys — own enumerable string-keyed properties only.
Excluded — symbol keys and non-enumerable properties are skipped.
Nested values — stay as-is inside the value slot (not flattened).
Rebuild objects with _.fromPairs() or native Object.fromEntries().
Wrap Up
Conclusion
_.toPairs() turns objects into iterable [key, value] arrays, making property loops and transformations straightforward. Pair it with _.fromPairs() when you need to convert back after mapping or filtering.
For plain objects in modern JavaScript, Object.entries() is equivalent. Choose Lodash when you want consistency in a Lodash pipeline. Next in the series: _.toPairsIn() for inherited properties.
Use _.toPairs when you need array methods on object entries
Destructure tuples as [key, value] in callbacks
Round-trip with _.fromPairs after transforming pairs
Prefer Object.entries in greenfield native-only code
Remember nested values stay nested in each pair
❌ Don’t
Expect _.toPairs to flatten nested objects recursively
Assume symbol keys or non-enumerable props are included
Mutate the returned pairs array if you still need the original object shape unchanged elsewhere—clone if needed
Use _.toPairs when you only need inherited keys (use _.toPairsIn)
Serialize passwords or secrets to JSON without filtering sensitive keys first
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about _.toPairs()
Use these when converting objects to iterable entry arrays.
5
Core concepts
🔗01
Object → pairs
[key, value][]
Core
📦02
Non-mutating
New array.
Important
🗃️03
Own keys
Enumerable strings.
Scope
🔀04
fromPairs
Inverse rebuild.
Pair
🛠️05
vs entries
Native twin.
Compare
❓ Frequently Asked Questions
_.toPairs() converts an object into an array of [key, value] pairs—one tuple per own enumerable string-keyed property. It is the Lodash equivalent of Object.entries().
No. _.toPairs() reads the object and returns a new array. The source object is unchanged.
No. Nested object values remain nested inside the value slot of each pair. To flatten deeply, use a separate utility or map recursively yourself.
For plain objects they behave the same in modern JavaScript. _.toPairs() is useful for consistency in Lodash pipelines and pairs with _.fromPairs() on the array side.
_.toPairs() includes only own enumerable properties. _.toPairsIn() also walks inherited enumerable properties on the prototype chain.
_.fromPairs() (array method) rebuilds an object from [key, value] pairs. Object.fromEntries() is the native equivalent.
Did you know?
Some older tutorials claim _.toPairs() recurses into nested objects—it does not. A nested object becomes the value in one pair. Also, modern JavaScript guarantees insertion order for string keys (with integer-like keys sorted first), so pair order is predictable in current engines.