Ramda.js R.fromPairs() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
List

Definition

A helper that builds a new object from a list of [key, value] pairs. Each pair becomes one property, and if a key repeats, the rightmost pair wins. It has been part of Ramda List since v0.3.0 (stable, not deprecated, experimental, or non-standard).

Why not the native method? Object.fromEntries() does the same job but needs ES2019. R.fromPairs works on older engines too, and it is a plain one-argument function that fits straight into R.pipe, usually right after R.toPairs.

Syntax

Call R.fromPairs. Start with this line.

Ramda
R.fromPairs(pairs)
CallWhat it does
R.fromPairs(pairs)Primary signature.
R.fromPairs(...)Call the list helper.

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

Library declarations
Ramda
R.fromPairs(pairs)

Parameters

ParameterDescription
pairsRequired. An array of [key, value] arrays

Return Value

Return ValueDescription
*A new plain object. The input list is not changed

Ramda Examples

Example 1 — Official Sample

Three pairs in, one object out.

Ramda
const obj = R.fromPairs([["a", 1], ["b", 2], ["c", 3]]);

console.log(obj);
// → { a: 1, b: 2, c: 3 }
Try It Yourself

How It Works

  1. Pairs. Each inner array holds a key at index 0 and a value at index 1.
  2. Loop. R.fromPairs starts with {} and sets one property per pair, in order.
  3. Result. You get a new plain object, { a: 1, b: 2, c: 3 }.
  4. Untouched input. The list of pairs is not modified.

Example 2 — Duplicate Keys: The Rightmost Pair Wins

Later settings override earlier ones, which is handy for defaults followed by overrides.

Ramda
const settings = R.fromPairs([
  ["theme", "light"],
  ["lang", "en"],
  ["theme", "dark"]
]);

console.log(settings);
// → { theme: "dark", lang: "en" }
Try It Yourself

How It Works

  1. First theme. ["theme", "light"] sets theme to "light".
  2. Language. ["lang", "en"] adds a second key.
  3. Override. ["theme", "dark"] writes to the same key, so "dark" replaces "light".
  4. Order. theme keeps its original first position. Only its value changes.

Example 3 — Remove Empty Fields From an Object

The classic round trip: object to pairs, filter the pairs, then back to an object.

Ramda
const dropEmpty = R.pipe(
  R.toPairs,
  R.filter(([key, value]) => value != null),
  R.fromPairs
);

console.log(dropEmpty({ name: "Ada", email: null, age: 36 }));
// → { name: "Ada", age: 36 }
Try It Yourself

How It Works

  1. To pairs. R.toPairs gives [["name","Ada"], ["email",null], ["age",36]].
  2. Filter. R.filter keeps pairs whose value is not null or undefined, which drops email.
  3. Back to an object. R.fromPairs rebuilds { name: "Ada", age: 36 }.
  4. Reusable. dropEmpty works on any object, and the original stays unchanged.

Example 4 — Build a Lookup Table From a List

Map each record to a [key, value] pair, then collect the pairs.

Ramda
const users = [
  { id: "u1", name: "Ada" },
  { id: "u2", name: "Lin" }
];

const nameById = R.fromPairs(R.map(u => [u.id, u.name], users));

console.log(nameById);
// → { u1: "Ada", u2: "Lin" }
Try It Yourself

How It Works

  1. Make pairs. R.map turns each user into [id, name]: [["u1","Ada"], ["u2","Lin"]].
  2. Collect. R.fromPairs turns those pairs into one object.
  3. Fast lookups. nameById.u2 is "Lin", with no searching through the list.
  4. Whole records? To keep the full record as the value, R.indexBy(R.prop("id")) is shorter.

Example 5 — Parse a Simple Query String

Split the text into pairs, then build the object.

Ramda
const parseQuery = R.pipe(
  R.split("&"),
  R.map(R.split("=")),
  R.fromPairs
);

console.log(parseQuery("page=2&sort=name"));
// → { page: "2", sort: "name" }
Try It Yourself

How It Works

  1. Split on &. "page=2&sort=name" becomes ["page=2", "sort=name"].
  2. Split on =. Each part becomes a pair: [["page","2"], ["sort","name"]].
  3. Build. R.fromPairs returns { page: "2", sort: "name" }.
  4. Values stay strings. "2" is text. For real URLs with encoded characters, use the browser’s URLSearchParams.

Browser & Runtime Support

R.fromPairs has been a Ramda List helper since v0.3.0. It uses a plain loop with property assignment, so it runs anywhere Ramda runs, including engines without the ES2019 Object.fromEntries. In the browser, load it from a CDN or a bundler. In Node.js, Bun, or Deno, run npm install ramda.

✓ Stable · Ramda 0.3.0+

R.fromPairs()

Support depends on the Ramda version you load, not on a browser feature. Your own code must also be valid in that runtime. For example, arrow functions and destructuring need an ES2015 engine.

100% Modern browsers & runtimes
Google Chrome Modern versions · Desktop & Mobile
Full support
Mozilla Firefox Modern versions · Desktop & Mobile
Full support
Apple Safari Modern versions · macOS & iOS
Full support
Microsoft Edge Chromium-based
Full support
Opera Modern versions
Full support
Samsung Internet Modern versions · Android
Full support
Android WebView Modern WebView
Full support
Internet Explorer Not a target for current Ramda releases
Legacy
Node.js Maintained LTS · npm install ramda
Supported
Bun import from "ramda"
Supported
Deno import from "npm:ramda"
Supported
R.fromPairs Ramda 0.3.0+

Bottom line: Safe for production in any modern browser or JavaScript runtime once Ramda is loaded. The labs on this page use [email protected] from a CDN.

Frequently Asked Questions

R.fromPairs(pairs) builds a new object from a list of [key, value] pairs. Docs sample: R.fromPairs([['a', 1], ['b', 2], ['c', 3]]) //=> {a: 1, b: 2, c: 3}.
The rightmost pair wins. R.fromPairs([['a', 1], ['a', 2]]) gives {a: 2}. No error or warning is raised, so remove duplicates first if they matter.
Both turn pairs into an object. Object.fromEntries is native (ES2019) and accepts any iterable, including a Map. R.fromPairs reads an array-like list by index, works on older engines, and is a curried function that fits into R.pipe.
R.fromPairs takes one list of pairs: [['a', 1], ['b', 2]]. R.zipObj takes two separate lists, one of keys and one of values: R.zipObj(['a', 'b'], [1, 2]). Both return {a: 1, b: 2}.
Use R.toPairs(obj). R.fromPairs(R.toPairs(obj)) rebuilds a shallow copy of the object's own enumerable properties, which makes toPairs, map or filter, then fromPairs a common way to transform objects.
No. R.fromPairs has been part of Ramda since v0.3.0 and is stable. It is not deprecated, experimental, or non-standard.

Next: R.groupBy()

Learn how to group list items into an object of lists by key.

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