Ramda.js R.toPairsIn() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Object

Definition

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)
CallWhat 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

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 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']]
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 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']]
Try It Yourself

How It Works

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']]
Try It Yourself

How It Works

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.

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

const child = Object.create(
  { def: 1 },
  { own: { value: 2, enumerable: true } }
);

R.toPairsIn(child);
//=> [['own', 2], ['def', 1]]
Try It Yourself

How It Works

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.

Ramda
const F = function () { this.x = 1; };
F.prototype.y = 2;

R.map(R.toPairsIn, [new F(), Object.create({ z: 3 })]);
//=> [[['x', 1], ['y', 2]], [['z', 3]]]

const inheritedY = R.pipe(
  R.toPairsIn,
  R.filter(function (pair) { return pair[0] === 'y'; })
);

inheritedY(new F());
//=> [['y', 2]]
Try It Yourself

How It Works

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.

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

Continue to R.unwind()

Learn how to explode one array field into one object per item using Ramda R.unwind().

R.unwind() 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