Underscore.js _.pairs() Method

Beginner
5 min read
Updated: Nov 2026
4 examples
Object

Definition

Convert an object into a list of [key, value] pairs (official Underscore docs). The opposite of _.object. Own enumerable string keys only. Stable helper — not deprecated.

Pass the required arguments shown below. Underscore object helpers usually return a new value — check whether the source object is mutated.

Syntax

Call _.pairs. Start with this line.

Underscore
_.pairs(object)
CallWhat it does
_.pairs(object)Primary signature.
_.pairs(...)Call with the arguments your case needs.

Load Underscore with import _ from "underscore" (or the UMD CDN build) so these helpers are available as _.

Library declarations
Underscore
_.pairs(object)

Parameters

ParameterDescription
objectRequired. Source to read own keys from

Return Value

Return ValueDescription
*Array of [key, value] arrays

Underscore.js Examples

Example 1 — Official: Three Pairs

The docs turn a small object into [key, value] arrays.

Underscore
_.pairs({one: 1, two: 2, three: 3});
// → [["one", 1], ["two", 2], ["three", 3]]
Try It Yourself

How It Works

  1. Source. Three own properties: one, two, three.
  2. Each key. Underscore pushes [key, value] into a new array.
  3. Order. Entries follow the object’s own enumerable key order.
  4. Official result. Three nested arrays of length 2.

Example 2 — Pairs vs Keys and Values

Same object, three shapes: names, values, or both.

Underscore
var obj = {one: 1, two: 2, three: 3};

_.keys(obj);    // → ["one", "two", "three"]
_.values(obj);  // → [1, 2, 3]
_.pairs(obj);   // → [["one", 1], ["two", 2], ["three", 3]]
Try It Yourself

How It Works

  1. keys. Names only — see _.keys.
  2. values. Values only — see _.values.
  3. pairs. Zip them together so each name stays with its value.
  4. Pick. Use pairs when you need both while iterating.

Example 3 — Round-Trip with _.object

Pairs out, object back — the documented inverse.

Underscore
var obj = {one: 1, two: 2, three: 3};
var list = _.pairs(obj);
// → [["one", 1], ["two", 2], ["three", 3]]

_.object(list);
// → {one: 1, two: 2, three: 3}
Try It Yourself

How It Works

  1. Split. _.pairs flattens the object into entries.
  2. Rebuild. _.object reads each [key, value].
  3. Same shape. You get an equivalent plain object back.
  4. Use case. Edit the list (sort, filter), then call _.object.

Example 4 — Empty Object

No own keys means an empty list of pairs.

Underscore
_.pairs({});           // → []
_.pairs({a: 1});       // → [["a", 1]]
_.pairs({name: "moe", age: 50});
// → [["name", "moe"], ["age", 50]]
Try It Yourself

How It Works

  1. Empty. Nothing to list → [].
  2. One key. A single pair of length 2.
  3. Two keys. Two pairs in own-key order.
  4. Pattern. Length of the result equals the number of own enumerable keys.

Browser & Runtime Support

_.pairs ships with Underscore.js (1.x). It runs anywhere Underscore runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install underscore. On modern engines, native Object.entries is a close equivalent.

✓ Stable · Underscore 1.x

_.pairs()

Available in [email protected] (UMD / ESM). Works in evergreen browsers and current Node LTS when Underscore is loaded.

100% With Underscore 1.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
_.pairs Underscore 1.x+

Bottom line: Safe for production once Underscore is on the page or in your bundle. Not a native browser API by itself — load Underscore first (or use Object.entries). Prefer a pinned CDN version (e.g. [email protected]).

Frequently Asked Questions

_.pairs(object) converts an object into an array of [key, value] pairs. Official example: _.pairs({one: 1, two: 2, three: 3}) returns [["one", 1], ["two", 2], ["three", 3]].
No. It lists only own enumerable properties. Prototype properties are skipped.
_.keys returns names, _.values returns values, and _.pairs returns both together as [key, value] arrays so each name stays attached to its value.
For plain objects they produce the same structure. _.pairs adds Underscore's consistent handling; Object.entries is the native ES2017 equivalent.
Use _.object(pairs) — the opposite of _.pairs. _.object(_.pairs(obj)) rebuilds an equivalent object.
No. It is a stable Underscore object helper. Load Underscore 1.x and call _.pairs(object).

Next: _.invert()

Swap keys and values to build a reverse lookup object.

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