Ramda.js R.mergeAll() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
List

Definition

R.mergeAll(list) combines an array of objects into one new object. When the same key appears more than once, the last object wins (official Ramda docs). It works like Object.assign({}, ...list) — a fresh, shallow copy that never touches the inputs.

Stable since v0.10.0: R.mergeAll is a core Ramda list function. It is not deprecated, experimental, or non-standard.

Syntax

Call R.mergeAll. Start with this line.

Ramda
R.mergeAll(list) — one argument Duplicate keys Last object wins Depth Shallow — nested objects are replaced, not combined Empty / null list {}
CallWhat it does
R.mergeAll(list) — one argument Duplicate keys Last object wins Depth Shallow — nested objects are replaced, not combined Empty / null list {}Primary signature.
R.mergeAll(...)Call the list helper.

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

Library declarations
Ramda
R.mergeAll(list) — one argument Duplicate keys Last object wins Depth Shallow — nested objects are replaced, not combined Empty / null list {}

Parameters

ParameterDescription
listRequired. Array of objects; null / undefined items are skipped — never changed

Return Value

Return ValueDescription
*A new object with every own key; the last value for each key wins

Ramda Examples

Example 1 — Official Samples

Merge three objects with different keys, then three with a repeated key.

Ramda
console.log(R.mergeAll([{ foo: 1 }, { bar: 2 }, { baz: 3 }]));
// { foo: 1, bar: 2, baz: 3 }

console.log(R.mergeAll([{ foo: 1 }, { foo: 2 }, { bar: 2 }]));
// { foo: 2, bar: 2 }
Try It Yourself

How It Works

  1. No clashes. Each object adds a new key, so all three end up in the result.
  2. A clash. foo appears twice; the second object comes later, so foo is 2.
  3. Fresh object. The result is a new object; the inputs are not modified.

Example 2 — Layered Settings (Later Wins)

Combine defaults, saved preferences, and session choices — most important last.

Ramda
const defaults = { theme: 'light', fontSize: 14, lang: 'en' };
const saved    = { fontSize: 16 };
const session  = { theme: 'dark' };

console.log(R.mergeAll([defaults, saved, session]));
// { theme: 'dark', fontSize: 16, lang: 'en' }

console.log(defaults);
// { theme: 'light', fontSize: 14, lang: 'en' }  (unchanged)
Try It Yourself

How It Works

  1. Base layer. defaults provides all three keys.
  2. Override. saved replaces fontSize with 16.
  3. Top layer. session replaces theme with 'dark'; lang stays 'en'.
  4. Safe. defaults is not modified, so it can be reused for the next user.

Example 3 — Build a Lookup Object from a List

Turn each user into a one-key object, then merge them all.

Ramda
const users = [
  { id: 'u1', name: 'Ann' },
  { id: 'u2', name: 'Bob' }
];

const toLookup = R.pipe(
  R.map(u => ({ [u.id]: u.name })),
  R.mergeAll
);

console.log(toLookup(users)); // { u1: 'Ann', u2: 'Bob' }
Try It Yourself

How It Works

  1. Small objects. R.map turns each user into { u1: 'Ann' } and { u2: 'Bob' }. The [u.id] syntax uses the value as the key.
  2. Merge. R.mergeAll combines the list of one-key objects into a single lookup.
  3. Pipe-ready. R.mergeAll takes one argument, so it slots straight into R.pipe.
  4. Alternative. To keep the whole user object as the value, R.indexBy(R.prop('id')) does this in one step.

Example 4 — Shallow Merge vs Deep Merge

Nested objects are replaced, not combined. Fold with R.mergeDeepRight when you need a deep merge.

Ramda
const parts = [{ a: { x: 1 } }, { a: { y: 2 } }];

console.log(R.mergeAll(parts));                     // { a: { y: 2 } }
console.log(R.reduce(R.mergeDeepRight, {}, parts)); // { a: { x: 1, y: 2 } }
Try It Yourself

How It Works

  1. Same top-level key. Both objects have a, so the later one wins.
  2. Replaced whole. R.mergeAll doesn’t look inside a — { x: 1 } is simply replaced by { y: 2 }.
  3. Deep fold. R.reduce merges the parts one by one with R.mergeDeepRight, which combines nested objects.
  4. Result. The deep version keeps both x and y.

Example 5 — Optional Pieces with null

null and undefined items are skipped, which makes conditional properties easy.

Ramda
const makeUser = (name, isAdmin, email) => R.mergeAll([
  { name },
  isAdmin ? { role: 'admin' } : null,
  email ? { email } : undefined
]);

console.log(makeUser('Ann', true, '[email protected]'));
// { name: 'Ann', role: 'admin', email: '[email protected]' }

console.log(makeUser('Bob', false));
// { name: 'Bob' }
Try It Yourself

How It Works

  1. Always included. { name } is shorthand for { name: name }.
  2. Maybe included. Each condition returns either a small object or null / undefined.
  3. Skipped. R.mergeAll ignores the null and undefined items, so Bob gets only name.
  4. No empty keys. Bob has no role or email keys at all — not even undefined ones.

Browser & Runtime Support

R.mergeAll() is plain JavaScript inside Ramda (available since v0.10.0). It uses Object.assign when available and a built-in fallback otherwise, so support depends only on loading Ramda.

✓ Ramda 0.10.0+ · Any JS runtime

Ramda.js R.mergeAll()

The UMD build (ramda.min.js) is compiled to ES5 syntax, so it runs in Chrome, Firefox, Safari, and Edge. Via npm it works in Node.js, Deno, and Bun with require or import. The arrow functions, shorthand properties, and computed keys in some examples need an ES2015+ engine, which every modern browser has.

100% With Ramda loaded
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
R.mergeAll() Universal

Bottom line: Safe in any project that includes Ramda. Load ramda.min.js from a CDN in the browser, or npm install ramda for Node, Deno, and Bun. These labs load [email protected] from jsDelivr.

Frequently Asked Questions

R.mergeAll(list) takes an array of objects and returns one new object containing all their own properties. If a key appears more than once, the value from the last object wins. Official sample: R.mergeAll([{foo: 1}, {foo: 2}, {bar: 2}]) returns {foo: 2, bar: 2}.
No. It copies everything into a brand-new empty object, so none of the input objects are modified. Nested objects are shared by reference, though, because the merge is shallow.
No. It is shallow: a nested object in a later item replaces the earlier one completely. For a deep merge of a list, use R.reduce(R.mergeDeepRight, {}, list).
R.mergeAll(list) behaves like Object.assign({}, ...list): it always starts from a fresh object, takes the objects as one array, and skips null and undefined items. It is a curried, one-argument function, so it fits at the end of R.pipe.
An empty object {}. R.mergeAll(null) and R.mergeAll(undefined) also return {} instead of throwing.
No. R.mergeAll has been a stable Ramda list function since v0.10.0. It is not deprecated, experimental, or non-standard.

Next: R.move()

Move a list item to a new position without mutating the list.

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