Ramda.js R.toPairs() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Object

Definition

Ramda’s R.toPairs() answers a zip question: what are this object’s own enumerable keys and values, as a list of two-item arrays? You pass an object. You get [[key, value], ...]. Prototype methods do not appear. A key whose value is undefined still appears.

The official sample is the whole idea. R.toPairs({a: 1, b: 2, c: 3}) is [['a', 1], ['b', 2], ['c', 3]]. Native JavaScript is Object.entries. Need only names? That is R.keys. Need only data? That is R.values. Need inherited names too? That is the next helper, R.toPairsIn. Need to rebuild an object from pairs? That is R.fromPairs.

Syntax

Call R.toPairs. Start with this line.

Ramda
R.toPairs(obj)
CallWhat it does
R.toPairs(obj)Primary signature.
R.toPairs(...)Call the object helper.

Prefer import { toPairs } from "ramda" when you want a named import.

Library declarations
Ramda
R.toPairs(obj)

Parameters

ParameterDescription
objRequired. Object. The record to extract from. Arrays work: indexes become the keys. Unlike R.keys, null is not turned into [] — a for…in on null throws.

Return Value

Return ValueDescription
Array of pairsEach leftover is [key, value] from an own enumerable property. The docs note that order is not guaranteed across JS platforms. The source object is not mutated.

Ramda Examples

📚 Getting Started

The official pair list, then the same object split into keys and values.

Example 1 — Official Object Pairs

Own enumerable fields come back as [key, value] arrays.

Ramda
R.toPairs({ a: 1, b: 2, c: 3 });
//=> [['a', 1], ['b', 2], ['c', 3]]
Try It Yourself

How It Works

Each leftover is a two-item array: the name, then the value. That is the docs sample from ramdajs.com. The docs also note that order is not guaranteed across every JS platform.

Example 2 — vs keys and values

Same object. keys is names. values is data. toPairs is both.

Ramda
const obj = { a: 1, b: 2, c: 3 };

R.keys(obj);
//=> ['a', 'b', 'c']

R.values(obj);
//=> [1, 2, 3]

R.toPairs(obj);
//=> [['a', 1], ['b', 2], ['c', 3]]
Try It Yourself

How It Works

If you zip R.keys(obj) with R.values(obj) you get the same leftover as toPairs, as long as both lists share the same own-enumerable walk. Prefer toPairs when you need each name glued to its leftover.

📈 Practical Patterns

Own vs inherited pairs, a round trip with fromPairs, then filter pairs and rebuild.

Example 3 — Own vs toPairsIn

toPairs lists own pairs. toPairsIn also includes enumerable names on the prototype.

Ramda
const F = function () { this.x = 'X'; };
F.prototype.y = 'Y';
const f = new F();

R.toPairs(f);
//=> [['x', 'X']]

R.toPairsIn(f);
//=> [['x', 'X'], ['y', 'Y']]
Try It Yourself

How It Works

x is assigned on the instance. y lives on F.prototype and is enumerable, so toPairsIn sees it. Next Object helper is toPairsIn. JSON field lists almost always want toPairs, not toPairsIn.

Example 4 — fromPairs Round Trip

Pairs rebuild an object. An empty object is []. Array indexes become string keys.

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

R.fromPairs(R.toPairs(obj));
//=> {a: 1, b: 2}

R.toPairs({});
//=> []

R.toPairs(['x', 'y']);
//=> [['0', 'x'], ['1', 'y']]
Try It Yourself

How It Works

fromPairs is the inverse for own enumerable string keys. Arrays are objects whose own keys are index strings, so toPairs lists '0' and '1'. Native Object.entries is the same leftover on a plain object.

Example 5 — Filter Pairs, Then Rebuild

Keep pairs whose leftover is greater than 1. fromPairs writes the leftover object.

Ramda
const keepBig = R.pipe(
  R.toPairs,
  R.filter(function (pair) { return pair[1] > 1; }),
  R.fromPairs
);

keepBig({ a: 1, b: 2, c: 3 });
//=> {b: 2, c: 3}

R.map(R.toPairs, [{ a: 1 }, { b: 2, c: 3 }]);
//=> [[['a', 1]], [['b', 2], ['c', 3]]]
Try It Yourself

How It Works

Arity 1 makes toPairs a clean first step in a pipe and a fine mapper. Filter sees pair[1] as the leftover. fromPairs writes the leftover object. Native spread would need Object.fromEntries instead.

Browser Support

R.toPairs() is ordinary JavaScript once Ramda is loaded. Logos use the shared browser-image-sprite.png sprite from this project.

✓ Ramda 0.4.0+ · Any JS runtime

Ramda.js R.toPairs()

Load Ramda 0.4.0 or later via CDN or npm, then call R.toPairs with an object. No extra browser API is required.

100% With Ramda 0.4.0+
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
R.toPairs() Universal

Bottom line: Safe in any project that includes Ramda 0.4.0 or later. Use a CDN build such as ramda.min.js in the browser or install ramda from npm for Node. These labs use [email protected].

Frequently Asked Questions

R.toPairs(obj) returns an array of [key, value] arrays from the object's own enumerable properties. Inherited prototype names do not appear. Added in v0.4.0.
R.toPairs({a: 1, b: 2, c: 3}) is [['a', 1], ['b', 2], ['c', 3]].
keys lists names. values lists data. toPairs lists both as pairs. Native Object.entries is the same leftover on a plain object, but it is data-first and throws on null. toPairs is curried.
toPairs uses only own properties (hasOwn). toPairsIn also includes enumerable inherited names from the prototype.
The docs say order is not guaranteed across JS platforms. Modern engines usually follow insertion order for string keys, but you should not depend on a sort.
No. R.toPairs is a stable Ramda object helper from v0.4.0. It is not deprecated, experimental, or non-standard.

Continue to R.toPairsIn()

Learn how to list own and enumerable prototype key-value pairs using Ramda R.toPairsIn().

R.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.

6 people found this page helpful