Ramda.js R.zipObj() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
List

Definition

R.zipObj(keys, values) returns a new object: the key at index 0 gets the value at index 0, the key at index 1 gets the value at index 1, and so on. It is the object version of R.zip (official Ramda docs).

Stable since v0.3.0: R.zipObj is not deprecated, experimental, or non-standard. Warning: never feed it untrusted keys — a key named '__proto__' changes the result’s prototype instead of creating a property.

Syntax

Call R.zipObj. Start with this line.

Ramda
R.zipObj(keys, values) or R.zipObj(keys)(values)
CallWhat it does
R.zipObj(keys, values) or R.zipObj(keys)(values)Primary signature.
R.zipObj(...)Call the list helper.

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

Library declarations
Ramda
R.zipObj(keys, values) or R.zipObj(keys)(values)

Parameters

ParameterDescription
keysRequired. Array of property names (non-strings are turned into strings)
valuesOptional. Array of values; omit it to get a reusable function

Return Value

Return ValueDescription
*A new plain object with min(keys.length, values.length) assignments

Ramda Examples

Example 1 — Official: Keys Meet Values

The sample from the Ramda docs: three keys, three values, one object.

Ramda
console.log(R.zipObj(['a', 'b', 'c'], [1, 2, 3]));
// { a: 1, b: 2, c: 3 }
Try It Yourself

How It Works

  1. Index 0. Key 'a' gets value 1.
  2. Index 1. Key 'b' gets value 2.
  3. Index 2. Key 'c' gets value 3.
  4. Result. One new object with three properties.

Example 2 — Turn a Data Row into a Record

A header row names the columns; a data row holds the values. zipObj joins them.

Ramda
const header = ['name', 'age', 'city'];
const row = ['Ana', 31, 'Paris'];

const user = R.zipObj(header, row);

console.log(user);       // { name: 'Ana', age: 31, city: 'Paris' }
console.log(user.city);  // Paris
Try It Yourself

How It Works

  1. Columns. header supplies the property names.
  2. Values. row supplies the data in the same column order.
  3. Zip. 'name' pairs with 'Ana', 'age' with 31, 'city' with 'Paris'.
  4. Use it. The result is a normal object, so user.city reads 'Paris'.

Example 3 — Uneven Lists and Duplicate Keys

Extra items are dropped, and a repeated key keeps only its last value.

Ramda
console.log(R.zipObj(['a', 'b', 'c'], [1]));        // { a: 1 }
console.log(R.zipObj(['a'], [1, 2, 3]));            // { a: 1 }
console.log(R.zipObj(['a', 'b', 'a'], [1, 2, 3]));  // { a: 3, b: 2 }
Try It Yourself

How It Works

  1. Fewer values. min(3, 1) is 1, so keys 'b' and 'c' are skipped.
  2. Fewer keys. min(1, 3) is 1, so values 2 and 3 are skipped.
  3. Duplicate key. 'a' is set to 1, then overwritten with 3.
  4. No errors. All of this happens silently, so check lengths and duplicates when the data matters.

Example 4 — zipObj vs zip + fromPairs

The docs say zipObj is the same as zipping first and building the object second.

Ramda
const keys = ['x', 'y'];
const values = [10, 20];

const direct = R.zipObj(keys, values);
const twoSteps = R.fromPairs(R.zip(keys, values));

console.log(direct);                      // { x: 10, y: 20 }
console.log(twoSteps);                    // { x: 10, y: 20 }
console.log(R.equals(direct, twoSteps));  // true
Try It Yourself

How It Works

  1. Direct. R.zipObj assigns each key and value straight onto a new object.
  2. Two steps. R.zip builds [['x', 10], ['y', 20]], then R.fromPairs turns those pairs into an object.
  3. Same result. R.equals confirms both objects match.
  4. Prefer zipObj. It is shorter and skips the temporary list of pairs.

Example 5 — Turn Many Rows into Records

Leave out the values to get a reusable row converter, then map it over a table.

Ramda
const header = ['name', 'age'];
const rows = [
  ['Ana', 31],
  ['Ben', 25]
];

const toRecord = R.zipObj(header);

console.log(R.map(toRecord, rows));
// [{ name: 'Ana', age: 31 }, { name: 'Ben', age: 25 }]
Try It Yourself

How It Works

  1. Curry. R.zipObj(header) has no values yet, so it returns a function waiting for a row.
  2. Map. R.map calls toRecord once per row.
  3. Each row. ['Ana', 31] becomes { name: 'Ana', age: 31 }.
  4. Reuse. The same toRecord works for every table with this header.

Browser & Runtime Support

R.zipObj() is a plain loop inside Ramda 0.3.0+. Without Ramda, Object.fromEntries(keys.map((k, i) => [k, values[i]])) is close, but Object.fromEntries (ES2019) needs Chrome 73+, Firefox 63+, Safari 12.1+, Edge 79+, or Node 12+, and it does not cut to the shorter list.

✓ Ramda 0.3.0+ · Any JS runtime

Ramda.js R.zipObj()

The UMD build (ramda.min.js) is compiled to ES5 syntax, so it runs in Chrome, Firefox, Safari, and Edge, including older versions without Object.fromEntries. Via npm it works in Node.js, Deno, and Bun.

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.zipObj() Universal

Bottom line: Safe in any project with Ramda (check with npm ls 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].

Frequently Asked Questions

R.zipObj(keys, values) builds a new object where keys[i] becomes a property name and values[i] becomes its value. The official sample R.zipObj(['a', 'b', 'c'], [1, 2, 3]) returns { a: 1, b: 2, c: 3 }.
Only the shorter length is used. Extra keys or extra values are silently dropped, so R.zipObj(['a', 'b', 'c'], [1]) returns { a: 1 }. No error is thrown.
The last value wins, because each key is assigned in order and later assignments overwrite earlier ones. R.zipObj(['a', 'b', 'a'], [1, 2, 3]) returns { a: 3, b: 2 }.
Yes, the Ramda docs say zipObj is equivalent to pipe(zip, fromPairs). zipObj does it in a single pass without building the temporary list of pairs.
Use R.keys(obj) and R.values(obj). Passing them back into R.zipObj rebuilds an equal object. R.toPairs(obj) gives [key, value] pairs instead.
No. R.zipObj has been part of Ramda since v0.3.0 and is stable. It is not deprecated, experimental, or non-standard.

Next: R.zipWith()

Combine two lists position by position with your own function.

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