Lodash _.intersectionWith() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Array

Definition

Like _.intersection, but equality uses a comparator invoked as (arrVal, othVal). Return true when a pair should count as a match. Order and references follow the first array. Part of Lodash 4.x Array (since 4.0.0).

Pass the required arguments shown below. Lodash Array helpers usually return a new value — check whether the source array is mutated.

Syntax

Call _.intersectionWith on an array. Start with this line.

Lodash
_.intersectionWith([arrays], [comparator])
CallWhat it does
_.intersectionWith([arrays], [comparator])Primary signature.
_.intersectionWith(array)Call with an array argument.

Prefer import intersectionWith from "lodash/intersectionWith" when you want a smaller bundle.

Library declarations
Lodash
_.intersectionWith([arrays], [comparator])

Parameters

ParameterDescription
arraysOptional. Arrays to inspect; first sets order
comparatorOptional. (arrVal, othVal) → boolean

Return Value

Return ValueDescription
*New array of intersecting values

Lodash Examples

Example 1 — Official: Deep Equal With _.isEqual

Keep first-list objects that deeply equal an item in every other list.

Lodash
var objects = [{ x: 1, y: 2 }, { x: 2, y: 1 }];
var others  = [{ x: 1, y: 1 }, { x: 1, y: 2 }];

_.intersectionWith(objects, others, _.isEqual);
// → [{ x: 1, y: 2 }]
Try It Yourself

How It Works

  1. Comparator. _.isEqual checks deep structural equality.
  2. First object. Matches { x: 1, y: 2 } in others → kept.
  3. Second object. No deep match → skipped.
  4. Reference. Result keeps the object from objects, not others.

Example 2 — Custom Field Comparator

Match when both x and y are equal — ignore other fields.

Lodash
function sameXY(a, b) {
  return a.x === b.x && a.y === b.y;
}

_.intersectionWith(
  [{ x: 1, y: 2, tag: "a" }, { x: 3, y: 4, tag: "b" }],
  [{ x: 1, y: 2 }],
  sameXY
);
// → [{ x: 1, y: 2, tag: "a" }]
Try It Yourself

How It Works

  1. Rule. Equal if x and y both match.
  2. First. Coordinates match → kept (with its tag).
  3. Second. Coordinates differ → skipped.
  4. Use. Partial equality when deep equal would be too strict.

Example 3 — Numeric Tolerance

Treat numbers within 0.1 as the same.

Lodash
function near(a, b) {
  return Math.abs(a - b) < 0.1;
}

_.intersectionWith([1.0, 2.0, 3.0], [1.05, 4], near);
// → [1]
Try It Yourself

How It Works

  1. Rule. |a − b| < 0.1 counts as a match.
  2. 1.0. Near 1.05 → kept (shown as 1 in JSON).
  3. 2.0 / 3.0. No near neighbor in the second list → skipped.
  4. vs intersection. Plain _.intersection would keep nothing — 1 !== 1.05.

Example 4 — No Shared Match

If the comparator never returns true across lists, the result is empty.

Lodash
_.intersectionWith(
  [{ x: 1, y: 2 }],
  [{ x: 9, y: 9 }],
  _.isEqual
);
// → []
Try It Yourself

How It Works

  1. Compare. { x: 1, y: 2 } vs { x: 9, y: 9 }.
  2. No match. _.isEqual returns false.
  3. Result. [].
  4. Safe. No throw — check length before using the overlap.

Example 5 — Three Arrays by id

A value must match in every other array under the comparator.

Lodash
function sameId(a, b) {
  return a.id === b.id;
}

_.intersectionWith(
  [{ id: 1 }, { id: 2 }, { id: 3 }],
  [{ id: 2 }, { id: 4 }],
  [{ id: 2 }, { id: 5 }],
  sameId
);
// → [{ id: 2 }]
Try It Yourself

How It Works

  1. Rule. Match on id only.
  2. id 2. Present in both later arrays → kept.
  3. id 1 / 3. Missing from at least one list → skipped.
  4. All lists. Intersection requires a match in every array after the first.

Browser & Runtime Support

_.intersectionWith is a Lodash 4.x Array helper (added in 4.0.0). It runs anywhere Lodash runs — modern browsers (via CDN or bundle) and Node.js / Bun / Deno with npm install lodash.

✓ Stable · Lodash 4.0.0+

_.intersectionWith()

Available in [email protected] full builds and the lodash/intersectionWith modular import. Works in evergreen browsers and current Node LTS when Lodash is installed.

100% With Lodash 4.0.0+
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
_.intersectionWith Lodash 4.0.0+

Bottom line: Safe for production once Lodash 4.0.0+ is on the page or in your bundle. Prefer import intersectionWith from "lodash/intersectionWith" for smaller builds. For a single projected key, prefer _.intersectionBy.

Frequently Asked Questions

_.intersectionWith(...arrays, comparator) is like _.intersection, but equality uses your comparator(arrVal, othVal). Return true when a pair should count as a match. Order and references follow the first array.
No. It returns a new array of elements from the first array that match at least one element in every other array under your comparator.
Last. Pass every array first, then the comparator — same pattern as _.differenceWith and other *With helpers.
Yes. _.intersectionWith(objects, others, _.isEqual) is the official deep-equality pattern for object lists.
Use _.intersectionBy when a single iteratee projection (property string or unary function) is enough. Use _.intersectionWith for pairwise logic, tolerances, or deep compares.
Use import intersectionWith from "lodash/intersectionWith" or require("lodash/intersectionWith") for tree-shaking friendly bundles. Full build: import _ from "lodash" then _.intersectionWith.

Next: _.join()

Convert an array into a string with a separator — Lodash’s string join helper.

_.join() 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.

10 people found this page helpful