Lodash _.toPairs() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Object

Definition

Creates an array of own enumerable string-keyed [key, value] pairs for object. Part of Lodash 4.x Object (since 0.1.0; renamed from _.pairs in 4.0.0).

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

Syntax

Call _.toPairs. Start with this line.

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

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

Library declarations
Lodash
_.toPairs(object)

Parameters

ParameterDescription
objectRequired. Source whose own enumerable keys become pairs

Return Value

Return ValueDescription
*Array of [key, value] tuples

Lodash Examples

Example 1 — Official Object to Pairs

Turn a plain object into [key, value] tuples.

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

How It Works

  1. Own keys. Lodash lists enumerable own string keys.
  2. Pair. Each key becomes [key, value].
  3. Order. Follows the object’s enumeration order.
  4. Docs. Matches the official Lodash example.

Example 2 — Nested Values Stay Nested

toPairs does not flatten — nested objects remain values.

Lodash
_.toPairs({
  user: { name: "Ada" },
  active: true
});
// → [["user", { name: "Ada" }], ["active", true]]
Try It Yourself

How It Works

  1. Top level. Only first-level keys become pairs.
  2. Value slot. { name: "Ada" } stays an object.
  3. No flatten. Nested keys are not expanded.
  4. Deep work. Recurse yourself if you need deep pairs.

Example 3 — Own Keys vs toPairsIn

Inherited enumerable properties need toPairsIn.

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. Sees only own on the instance.
  2. Prototype. shared lives on the prototype.
  3. toPairsIn. Walks the chain and includes shared.
  4. Pick. Prefer toPairs for plain data objects.

Example 4 — Round-Trip with fromPairs

Pairs are easy to transform, then rebuild into an object.

Lodash
var pairs = _.toPairs({ a: 1, b: 2 });
// → [["a", 1], ["b", 2]]

_.fromPairs(pairs);
// → { a: 1, b: 2 }
Try It Yourself

How It Works

  1. Out. toPairs turns the object into an array.
  2. Work. You can map/filter pairs in between.
  3. In. fromPairs rebuilds a plain object.
  4. Native. Same idea as Object.fromEntries.

Example 5 — Transform Pairs Then Rebuild

A common pattern: uppercase keys via map + fromPairs.

Lodash
var pairs = _.toPairs({ a: 1, b: 2 });

var upper = _.map(pairs, function (pair) {
  return [pair[0].toUpperCase(), pair[1]];
});

_.fromPairs(upper);
// → { A: 1, B: 2 }
Try It Yourself

How It Works

  1. Pairs. Start with [["a",1],["b",2]].
  2. Map. Change each key with toUpperCase.
  3. Rebuild. fromPairs makes { A: 1, B: 2 }.
  4. Why. Array tools are simpler than manual object loops.

Browser & Runtime Support

_.toPairs is a Lodash Object helper (since 0.1.0 as _.pairs; 4.0.0 rename). It runs anywhere Lodash runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install lodash. Closest native cousin is Object.entries() (ES2017); Lodash also exposes the alias _.entries and pairs cleanly with _.fromPairs.

✓ Stable · Lodash 4.x

_.toPairs()

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

Bottom line: Safe for production once Lodash is loaded. Prefer import toPairs from "lodash/toPairs" for smaller builds. Ideal before mapping, filtering, or sorting object entries as arrays.

Frequently Asked Questions

_.toPairs(object) returns an array of [key, value] pairs for each own enumerable string-keyed property. Same idea as Object.entries().
No. It returns a new array. The source object is unchanged.
No. Nested values stay nested inside the value slot of each pair.
toPairs is own properties only. toPairsIn also includes inherited enumerable properties.
_.fromPairs(pairs) rebuilds an object from [key, value] pairs. Native: Object.fromEntries().
Use import toPairs from "lodash/toPairs" or require("lodash/toPairs"). Full build: import _ from "lodash" then _.toPairs. Alias: _.entries.

Next: _.toPairsIn()

Get [key, value] pairs including inherited enumerable properties.

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