Ramda.js R.zip() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
List

Definition

R.zip(list1, list2) returns a new list of pairs, matching items that sit at the same position in both lists. Like a zipper, it joins the two sides tooth by tooth and stops when the shorter side runs out (official Ramda docs).

Stable since v0.1.0: R.zip is not deprecated, experimental, or non-standard. JavaScript arrays have no built-in zip, which is why this helper is so common.

Syntax

Call R.zip. Start with this line.

Ramda
R.zip(list1, list2) or R.zip(list1)(list2)
CallWhat it does
R.zip(list1, list2) or R.zip(list1)(list2)Primary signature.
R.zip(...)Call the list helper.

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

Library declarations
Ramda
R.zip(list1, list2) or R.zip(list1)(list2)

Parameters

ParameterDescription
list1Required. Supplies the first item of every pair
list2Optional. Supplies the second item; omit it to get a reusable function

Return Value

Return ValueDescription
*A new array of min(list1.length, list2.length) pairs

Ramda Examples

Example 1 — Official: Pair Items by Position

The sample from the Ramda docs: match each number with the letter at the same index.

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

How It Works

  1. Index 0. 1 and 'a' become [1, 'a'].
  2. Index 1. 2 and 'b' become [2, 'b'].
  3. Index 2. 3 and 'c' become [3, 'c'].
  4. Result. Both lists have 3 items, so there are 3 pairs.

Example 2 — The Shorter List Wins

When the lengths differ, the result stops at the shorter list.

Ramda
console.log(R.zip([1, 2, 3], ['a']));  // [[1, 'a']]
console.log(R.zip(['a'], [1, 2, 3]));  // [['a', 1]]
console.log(R.zip([], [1, 2, 3]));     // []
Try It Yourself

How It Works

  1. Shorter length. min(3, 1) is 1, so only index 0 is paired.
  2. Dropped. 2 and 3 have no partner and are silently left out.
  3. Swap. Swapping the arguments flips each pair to ['a', 1]; the length stays 1.
  4. Empty. An empty list has length 0, so the result is [].

Example 3 — Turn Two Lists into an Object

Zip names with scores, then build an object from the pairs.

Ramda
const names = ['Ana', 'Ben', 'Cy'];
const scores = [90, 85, 77];

console.log(R.zip(names, scores));
// [['Ana', 90], ['Ben', 85], ['Cy', 77]]

console.log(R.fromPairs(R.zip(names, scores)));
// { Ana: 90, Ben: 85, Cy: 77 }
Try It Yourself

How It Works

  1. Zip. Each name is paired with the score at the same index.
  2. Key-value pairs. Each pair looks like [key, value].
  3. Object. R.fromPairs turns those pairs into { Ana: 90, Ben: 85, Cy: 77 }.
  4. Shortcut. R.zipObj(names, scores) does both steps in one call.

Example 4 — zip vs zipWith

zip keeps the pairs. zipWith combines each pair with a function.

Ramda
const base = [1, 2, 3];
const bonus = [10, 20, 30];

console.log(R.zip(base, bonus));             // [[1, 10], [2, 20], [3, 30]]
console.log(R.zipWith(R.add, base, bonus));  // [11, 22, 33]
Try It Yourself

How It Works

  1. zip. Same-index numbers are kept side by side as pairs.
  2. zipWith. R.zipWith calls R.add on each position: 1 + 10, 2 + 20, 3 + 30.
  3. Result. It returns plain numbers, not pairs.
  4. Rule of thumb. If you would R.map over the zipped pairs right away, use zipWith instead.

Example 5 — Pair Each Item with the Next One

Zip a list with its own tail to compare neighbors, here day-to-day temperature changes.

Ramda
const temps = [18, 21, 19, 24];
const days = R.zip(temps, R.tail(temps));

console.log(days);
// [[18, 21], [21, 19], [19, 24]]

console.log(R.map(([today, tomorrow]) => tomorrow - today, days));
// [3, -2, 5]
Try It Yourself

How It Works

  1. Shift. R.tail(temps) is [21, 19, 24] — the same list moved one step left.
  2. Zip. Each day lines up with the next day; the last day has no partner and drops off.
  3. Difference. Destructuring ([today, tomorrow]) unpacks each pair, and tomorrow - today gives the change.
  4. Alternative. R.aperture(2, temps) builds the same neighbor pairs.

Browser & Runtime Support

R.zip() is a plain loop inside Ramda 0.1.0+. JavaScript arrays have no built-in zip; the closest native version is a.slice(0, n).map((x, i) => [x, b[i]]) with n = Math.min(a.length, b.length), which works in every modern browser.

✓ Ramda 0.1.0+ · Any JS runtime

Ramda.js R.zip()

The UMD build (ramda.min.js) is compiled to ES5 syntax, so it runs in Chrome, Firefox, Safari, and Edge, including older versions. 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.zip() 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.zip(list1, list2) returns a new list of pairs, matching items by position: index 0 with index 0, index 1 with index 1, and so on. The official sample R.zip([1, 2, 3], ['a', 'b', 'c']) returns [[1, 'a'], [2, 'b'], [3, 'c']].
The result is cut to the shorter list, and the extra items of the longer list are silently dropped. R.zip([1, 2, 3], ['a']) returns [[1, 'a']]. No error is thrown.
R.zip always builds [a, b] pairs. R.zipWith(fn, list1, list2) calls fn(a, b) for each position and keeps the result, so R.zipWith(R.add, [1, 2], [10, 20]) returns [11, 22]. R.zip is the same as zipWith with a pair-making function.
Use R.zipObj(keys, values), or R.fromPairs(R.zip(keys, values)). Both turn ['Ana', 'Ben'] and [90, 85] into { Ana: 90, Ben: 85 }.
Use R.transpose. R.transpose([['Ana', 90], ['Ben', 85]]) returns [['Ana', 'Ben'], [90, 85]], giving the two original lists back.
No. R.zip has been part of Ramda since v0.1.0 and is stable. It is not deprecated, experimental, or non-standard.

Next: R.zipObj()

Build an object from a list of keys and a list of values.

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