Lodash _.toPairs() 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 _.toPairs() to turn objects into arrays of [key, value] tuples for iteration and transformation.

01

Core syntax

_.toPairs(object) returns an array of tuples.

02

Non-mutating

Reads the object; original stays unchanged.

03

Own keys only

Own enumerable string-keyed properties.

04

Iterate easily

Use forEach, map, or filter on pairs.

05

vs entries

Compare with native Object.entries().

06

fromPairs

Rebuild objects with _.fromPairs().

What Is _.toPairs()?

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

📝 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).
javascript
import toPairs from "lodash/toPairs";

const myObject = { a: 1, b: 2, c: 3 };
const pairs = toPairs(myObject);

// pairs -> [["a", 1], ["b", 2], ["c", 3]]

⚡ Quick Reference

TaskCode patternResult
Basic conversion_.toPairs({ a: 1, b: 2 })[["a", 1], ["b", 2]]
Iterate pairs_.toPairs(obj).forEach(...)Array iteration
Transform keys_.map(_.toPairs(o), ...)Map each tuple
Rebuild object_.fromPairs(pairs)Inverse operation
Native equivalentObject.entries(obj)Same for plain objects
Inherited keys_.toPairsIn(obj)See _.toPairsIn()
Mutates?
No

Returns new array

Keys
Own

Enumerable strings

Returns
[k,v][]

Tuple array

Inverse
fromPairs

Object rebuild

🧰 Parameters

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

object Required

The source object whose own enumerable string-keyed properties become pairs.

_.toPairs({ name: "Ada", age: 36 })
return value Output

Array of [key, value] tuples in property enumeration order.

[["name", "Ada"], ["age", 36]]
own keys Scope

Only properties on the object itself—not inherited prototype keys (use _.toPairsIn for those).

obj.hasOwnProperty("key")
nested values Behavior

Nested objects appear as the value in a pair—they are not recursively flattened to more pairs.

["a", { nested: 1 }]

Symbol-keyed properties are excluded. For Map objects, convert differently—_.toPairs targets plain object property enumeration.

Examples Gallery

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

📚 Getting Started

Convert plain objects into arrays of key-value tuples.

Example 1 — Basic object to pairs

Transform a simple object into an array of [key, value] tuples.

javascript
const myObject = { a: 1, b: 2, c: 3 };
const pairsArray = _.toPairs(myObject);

console.log(pairsArray);
// -> [["a", 1], ["b", 2], ["c", 3]]
Try It Yourself

How It Works

Each own enumerable string key becomes one two-element array in the result.

Example 2 — Iterate with forEach

Loop over object properties using array iteration after converting to pairs.

javascript
const user = { name: "John", age: 30, city: "New York" };

_.toPairs(user).forEach(([key, value]) => {
  console.log(key + ": " + value);
});
// name: John
// age: 30
// city: New York
Try It Yourself

📈 Practical Patterns

Nested values, transformations, round trips, and native alternatives.

Example 3 — Nested object values (not flattened)

_.toPairs() does not recurse into nested objects—the nested value stays in the tuple.

javascript
const nestedObject = { a: { nestedProp: 1 }, b: 2 };
const nestedPairs = _.toPairs(nestedObject);

console.log(nestedPairs);
// -> [["a", { nestedProp: 1 }], ["b", 2]]

Example 4 — Transform keys with map

Uppercase every key by mapping over pairs, then rebuild with _.fromPairs.

javascript
const config = { theme: "dark", lang: "en" };

const uppercased = _.fromPairs(
  _.map(_.toPairs(config), ([key, value]) => [key.toUpperCase(), value])
);

console.log(uppercased);
// -> { THEME: "dark", LANG: "en" }
Try It Yourself

Example 5 — Round trip with _.fromPairs()

Convert to pairs, modify, and convert back to an object.

javascript
const original = { x: 10, y: 20 };
const pairs = _.toPairs(original);
const restored = _.fromPairs(pairs);

console.log(restored);
// -> { x: 10, y: 20 }

🚀 Beyond the Basics

Native alternatives and when to pick Lodash.

Example 6 — _.toPairs() vs Object.entries()

For plain objects in modern JavaScript, both return the same pairs.

javascript
const obj = { a: 1, b: 2 };

const lodashPairs = _.toPairs(obj);
const nativePairs = Object.entries(obj);

console.log(JSON.stringify(lodashPairs) === JSON.stringify(nativePairs));
// -> true

🧠 How _.toPairs() Works

1

Enumerate keys

Lodash collects own enumerable string-keyed properties from the object.

Input
2

Build tuples

Each key is paired with its current value as a two-element array.

Pair
3

Return array

A new array of tuples is returned; the original object is untouched.

Output
=

Ready to iterate

Use array methods on the pairs or pass them to _.fromPairs() to rebuild an object.

📝 Notes

  • _.toPairs() does not mutate the source object—it returns a new array.
  • Only own enumerable string-keyed properties are included.
  • Nested object values are not flattened into more pairs.
  • Property order follows modern JavaScript enumeration rules (integer-like keys first, then strings in insertion order).
  • For inherited enumerable keys, use _.toPairsIn().
  • Rebuild objects with _.fromPairs() or native Object.fromEntries().

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.

💡 Best Practices

✅ Do

  • 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

Key Takeaways

Knowledge Unlocked

Five things to remember about _.toPairs()

Use these when converting objects to iterable entry arrays.

5
Core concepts
📦 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.

Practice _.toPairs() in the Live Editor

Convert objects to pairs, iterate entries, and transform 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