Ramda’s R.toPairsIn() answers a prototype-aware zip question: what enumerable keys and values does this object have, including names inherited from the prototype? You pass an object. You get [[key, value], ...]. Non-enumerable methods such as toString do not appear.
The official sample is the whole idea. A constructor assigns this.x = 'X' and sets F.prototype.y = 'Y'. For an instance f, R.toPairsIn(f) is [['x', 'X'], ['y', 'Y']]. Need own pairs only? That is the previous helper, R.toPairs. Need names instead of pairs? That is R.keysIn. Native JavaScript is a for…in loop.
Syntax
Call R.toPairsIn. Start with this line.
Ramda
R.toPairsIn(obj)
Call
What it does
R.toPairsIn(obj)
Primary signature.
R.toPairsIn(...)
Call the object helper.
Prefer import { toPairsIn } from "ramda" when you want a named import.
Library declarations
Ramda
R.toPairsIn(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 enumerable own or prototype property. The docs note that order is not guaranteed across JS platforms. The source object is not mutated.
Ramda Examples
📚 Getting Started
The official constructor sample, then the same instance compared with own-only pairs and with keysIn.
Example 1 — Official Instance Pairs
Own field x plus enumerable prototype field y come back as [key, value] arrays.
Ramda
const F = function () { this.x = 'X'; };
F.prototype.y = 'Y';
const f = new F();
R.toPairsIn(f);
//=> [['x', 'X'], ['y', 'Y']]
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 toPairs
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. JSON field lists almost always want toPairs, not toPairsIn.
📈 Practical Patterns
Names vs pairs, Object.create defaults, then map and filter inherited leftovers.
Example 3 — vs keysIn
keysIn is the same walk. toPairsIn glues each leftover to its name.
Ramda
const F = function () { this.x = 'X'; };
F.prototype.y = 'Y';
const f = new F();
R.keysIn(f);
//=> ['x', 'y']
R.toPairsIn(f);
//=> [['x', 'X'], ['y', 'Y']]
If you zip R.keysIn(f) with the leftovers you would get the same pair list, as long as both walks visit the same enumerable names. Prefer toPairsIn when you need each name glued to its leftover.
Example 4 — Empty Object and Object.create
An empty object is []. Enumerable prototype defaults still appear next to own fields.
Object.prototype.toString is usually non-enumerable, so {} has nothing for for…in to visit. own is an enumerable own field. def lives on the prototype and is enumerable, so it still appears. Native Object.entries(child) would list only own.
Example 5 — Map Instances and Filter Inherited Pairs
Arity 1 maps over a list of instances. Filter keeps only the prototype leftover.
Arity 1 makes toPairsIn a clean mapper and a clean first step in a pipe. Filter sees pair[0] as the name. The second record has no own fields, so only the enumerable prototype leftover z appears.
Compatibility
Browser Support
R.toPairsIn() 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.toPairsIn()
Load Ramda 0.4.0 or later via CDN or npm, then call R.toPairsIn 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.toPairsIn()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.toPairsIn(obj) returns an array of [key, value] arrays from enumerable properties on obj, including names inherited from the prototype. Non-enumerable names such as toString are skipped. Added in v0.4.0.
A constructor assigns this.x = 'X' and sets F.prototype.y = 'Y'. For an instance f, R.toPairsIn(f) is [['x', 'X'], ['y', 'Y']].
toPairs lists own enumerable pairs only (hasOwn). toPairsIn is a for-in loop, so enumerable prototype pairs count too. keysIn is the same walk but returns names instead of pairs.
R.toPairsIn(null) and R.toPairsIn(undefined) throw, because for-in cannot walk null. Guard the input if it can be empty.
No. Object.prototype.toString is usually non-enumerable, so R.toPairsIn({}) is []. Enumerate only names that for-in would visit.
No. R.toPairsIn is a stable Ramda object helper from v0.4.0. It is not deprecated, experimental, or non-standard.