Lodash _.intersectionBy() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Array

Definition

Like _.intersection, but each element is mapped through an iteratee before comparison. 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 _.intersectionBy on an array. Start with this line.

Lodash
_.intersectionBy([arrays], [iteratee=_.identity])
CallWhat it does
_.intersectionBy([arrays], [iteratee=_.identity])Primary signature.
_.intersectionBy(array)Call with an array argument.

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

Library declarations
Lodash
_.intersectionBy([arrays], [iteratee=_.identity])

Parameters

ParameterDescription
arraysOptional. Arrays to inspect; first sets order
iterateeOptional. Criterion per element; default identity

Return Value

Return ValueDescription
*New array of intersecting values

Lodash Examples

Example 1 — Official: Math.floor

Floats match when their floors match; the first array’s value is kept.

Lodash
_.intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor);
// → [2.1]
Try It Yourself

How It Works

  1. Project. floor(2.1)=2, floor(2.3)=2 — same key.
  2. Keep. Emit 2.1 from the first array (not 2.3).
  3. Skip 1.2. Floor 1 is missing from the second list.
  4. Iteratee last. Math.floor is the final argument.

Example 2 — Official: Property Shorthand

Compare objects by a field name string.

Lodash
_.intersectionBy([{ x: 1 }], [{ x: 2 }, { x: 1 }], "x");
// → [{ x: 1 }]
Try It Yourself

How It Works

  1. Shorthand. "x" reads each object’s x property.
  2. Match. First object has x: 1; second list also has x: 1.
  3. Reference. Result keeps the object from the first array.
  4. vs intersection. Plain _.intersection would fail — different object instances.

Example 3 — Match Users by id

Typical API use: keep first-list users whose ids appear elsewhere.

Lodash
var a = [{ id: 1, name: "Ada" }, { id: 2, name: "Bob" }];
var b = [{ id: 2, name: "Bobby" }, { id: 3, name: "Cy" }];

_.intersectionBy(a, b, "id");
// → [{ id: 2, name: "Bob" }]
Try It Yourself

How It Works

  1. Key. Compare on id only.
  2. Shared. Only id: 2 appears in both lists.
  3. Keep Ada’s list copy. Result is Bob from array a, not Bobby.
  4. Names differ. That is expected — equality ignored other fields.

Example 4 — No Shared Criterion

If no projected keys overlap, the result is empty.

Lodash
_.intersectionBy([1.2, 1.5], [2.3, 3.4], Math.floor);
// → []
Try It Yourself

How It Works

  1. Floors. First list → 1, 1; second → 2, 3.
  2. No overlap. Key 1 never appears in the second list.
  3. Result. [].
  4. Safe. No throw — check length before using the overlap.

Example 5 — Unique by Projected Key

Two first-array values that share a key contribute only once.

Lodash
_.intersectionBy([1.2, 1.3, 3.1], [1.9, 2.2], Math.floor);
// → [1.2]
// 1.2 and 1.3 both floor to 1 — only the first is kept
Try It Yourself

How It Works

  1. Shared key. Floor 1 exists in the second array (1.9).
  2. First wins. 1.2 is emitted; 1.3 is treated as a duplicate criterion.
  3. 3.1 skipped. Floor 3 is not in the second list.
  4. Design. Same “unique intersecting values” idea as _.intersection.

Browser & Runtime Support

_.intersectionBy 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+

_.intersectionBy()

Available in [email protected] full builds and the lodash/intersectionBy 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
_.intersectionBy Lodash 4.0.0+

Bottom line: Safe for production once Lodash 4.0.0+ is on the page or in your bundle. Prefer import intersectionBy from "lodash/intersectionBy" for smaller builds. For plain equality without an iteratee, use _.intersection.

Frequently Asked Questions

_.intersectionBy(...arrays, iteratee) is like _.intersection, but each element is mapped through iteratee first. Membership uses SameValueZero on those projected values. Order and references follow the first array.
No. It returns a new array of elements from the first array whose projected value appears in every other list.
Last. Pass every array first, then the iteratee — same pattern as _.differenceBy and other *By helpers.
Yes. A string like "x" is the _.property shorthand — compare objects by that field.
Results are unique by the projected criterion. If Math.floor makes 1.2 and 1.3 equal, only the first matching element from the first array is kept.
Use import intersectionBy from "lodash/intersectionBy" or require("lodash/intersectionBy") for tree-shaking friendly bundles. Full build: import _ from "lodash" then _.intersectionBy.

Next: _.intersectionWith()

Intersect arrays using a comparator function for each pair of values.

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