Ramda.js R.intersection() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Relation

Definition

Ramda’s R.intersection() answers a set-overlap question: which unique elements appear in both lists? You pass two lists of the same element type and get back a new array of shared values. Membership uses R.equals, so objects and nested arrays match by value. The result is a set — no duplicates. Order follows list1, not list2. It is not commutative when order differs. Cousin R.difference returns what is in the first list but not the second. Cousin R.innerJoin filters one list by a custom cross-list predicate and keeps duplicates from the first list. Previous helper is R.innerJoin. Next is R.lt.

The official sample is the whole idea. R.intersection([1,2,3,4], [7,6,5,4,3]) returns [4, 3] — values present in both lists, deduped, in the order they first appear when walking list1. On the same lists, R.difference([1,2,3,4], [7,6,5,4,3]) returns [1, 2].

Syntax

Call R.intersection. Start with this line.

Ramda
R.intersection(list1, list2)
CallWhat it does
R.intersection(list1, list2)Primary signature.
R.intersection(...)Call the relation helper.

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

Library declarations
Ramda
R.intersection(list1, list2)

Parameters

ParameterDescription
list1Required. Array. First list — shared elements are collected in this list's order. Not mutated.
list2Required. Array. Second list — membership source. An element from list1 is kept when R.equals finds a match in list2. Not mutated.

Return Value

Return ValueDescription
ArrayA new array: the set of elements found in both list1 and list2. No duplicates. Empty overlap → [].

Ramda Examples

📚 Getting Started

The official Ramda number sample and how it contrasts with first-minus-second difference.

Example 1 — Official Number Sample

Find shared values between two number lists. Result order follows the first list.

Ramda
R.intersection([1, 2, 3, 4], [7, 6, 5, 4, 3]);
//=> [4, 3]
Try It Yourself

How It Works

That is the docs sample from ramdajs.com. 4 and 3 appear in both lists. They are returned in list1 order: 4 before 3 because that is how they appear in [1,2,3,4].

Example 2 — vs R.difference on the Same Lists

Intersection keeps shared values. Difference keeps unique items from the first list that are missing from the second.

Ramda
R.intersection([1, 2, 3, 4], [7, 6, 5, 4, 3]);
//=> [4, 3]

R.difference([1, 2, 3, 4], [7, 6, 5, 4, 3]);
//=> [1, 2]
Try It Yourself

How It Works

Both helpers use R.equals for membership. Intersection answers “in both?” Difference answers “in first but not second?” On this input they are complementary: shared values vs unique leftovers from list1.

📈 Practical Patterns

innerJoin contrast, object overlap with R.equals, then curried partial application with R.__.

Example 3 — vs R.innerJoin — When Intersection Is Enough

For same-type lists, intersection dedupes with R.equals. innerJoin needs a predicate and keeps xs duplicates.

Ramda
R.intersection([1, 2, 2, 3], [3, 4]);
//=> [2, 3] — deduped

R.innerJoin(R.equals, [1, 2, 2, 3], [3, 4]);
//=> [2, 2, 3] — duplicates from xs kept

// innerJoin for cross-type joins:
R.innerJoin((record, id) => record.id === id, [{ id: 1 }, { id: 2 }], [2, 99]);
//=> [{ id: 2 }]
Try It Yourself

How It Works

When both lists hold the same type and you want unique shared values, intersection is simpler. Use innerJoin when lists hold different shapes or when duplicates from the first list must stay. Previous helper walkthrough: R.innerJoin.

Example 4 — Object Overlap with R.equals

{a: 1} in the first list matches {a: 1} in the second even though they are different object identities.

Ramda
R.intersection([{ a: 1 }, { b: 2 }], [{ a: 1 }, { c: 3 }]);
//=> [{ a: 1 }]
Try It Yourself

How It Works

Membership uses R.equals, not ===. The object from list1 is kept because its value equals an element in list2. {b: 2} has no match. Same pattern as R.difference object samples.

Example 5 — Curried Partial Application with R.__

Fix the second list once, then pass different first lists later.

Ramda
const allowlist = [3, 4, 5];
const overlapWith = R.intersection(R.__, allowlist);

overlapWith([1, 2, 3, 4]);
//=> [3, 4]

R.intersection(R.__, [2, 4])([1, 2, 3, 4]);
//=> [2, 4]
Try It Yourself

How It Works

R.intersection is arity 2 and supports R.__. R.intersection(R.__, allowlist) returns a function waiting for list1. Reuse the same overlap check against many incoming lists without repeating the fixed list.

Browser Support

R.intersection() is ordinary JavaScript once Ramda is loaded. Logos use the shared browser-image-sprite.png sprite from this project.

✓ Ramda 0.1.0+ · Any JS runtime

Ramda.js R.intersection()

Load Ramda 0.1.0 or later via CDN or npm, then call R.intersection with two lists. No extra browser API is required.

100% With Ramda 0.1.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.intersection() Universal

Bottom line: Safe in any project that includes Ramda 0.1.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.intersection(list1, list2) returns a new array of elements found in both lists. Duplicates are removed. Type: [*] → [*] → [*]. Arity 2, curried. Added in v0.1.0.
R.intersection([1,2,3,4], [7,6,5,4,3]) returns [4, 3] — the shared values from both lists, deduped, in list1 order.
intersection keeps items in both lists. difference(list1, list2) keeps unique items from list1 that are not in list2. On the official sample, difference returns [1, 2] while intersection returns [4, 3]. Both use R.equals for membership.
intersection compares same-type lists with R.equals and dedupes. innerJoin takes a custom binary predicate, can join different shapes (records vs ids), preserves xs order and duplicates from xs.
No. Objects and arrays use R.equals (value equality). R.intersection([{a: 1}, {b: 2}], [{a: 1}, {c: 3}]) returns [{a: 1}] because {a: 1} matches by value.
No. R.intersection is a stable Ramda relation helper from v0.1.0. It is not deprecated, experimental, or non-standard.

Continue to R.lt()

Learn strict less-than ordering with R.lt() — official samples, cousin comparisons, filters, and R.propSatisfies age predicates.

R.lt() Method →

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