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)
Call
What 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
Parameter
Description
obj
Required. 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 Value
Description
Array of pairs
Each 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.
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.
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']]
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.
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.
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.
Compatibility
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 ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll 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.
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.