Lodash _.intersection() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Array

Definition

Creates an array of unique values included in all given arrays, using SameValueZero equality. Order and references follow the first array. Part of Lodash 4.x Array.

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

Syntax

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

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

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

Library declarations
Lodash
_.intersection([arrays])

Parameters

ParameterDescription
arraysOptional. Arrays to inspect; first sets order

Return Value

Return ValueDescription
*New array of shared unique values

Lodash Examples

Example 1 — Official: Two Arrays

Keep values that appear in both lists.

Lodash
_.intersection([2, 1], [2, 3]);
// → [2]
Try It Yourself

How It Works

  1. First array. Official sample starts with [2, 1].
  2. Check 2. Present in [2, 3] → keep.
  3. Check 1. Missing from the second array → skip.
  4. Result. [2] — a new array; inputs unchanged.

Example 2 — Three Arrays

A value must appear in every argument to survive.

Lodash
_.intersection([1, 2, 3], [2, 3, 4], [2, 5]);
// → [2]
Try It Yourself

How It Works

  1. Scan first. Candidates: 1, 2, 3.
  2. Filter. 1 and 3 are missing from at least one later array.
  3. Keep 2. Present in all three lists.
  4. Rule. More arrays means a stricter filter.

Example 3 — No Overlap

Disjoint arrays yield an empty result.

Lodash
_.intersection([1, 2], [3, 4]);
// → []
Try It Yourself

How It Works

  1. Compare. Neither 1 nor 2 appears in [3, 4].
  2. Result. Empty array [].
  3. Safe. No throw — useful as a default when sets have no shared IDs.
  4. Check. Use result.length before assuming shared values exist.

Example 4 — Duplicates Collapse

Even if the first array repeats a value, the result lists it once.

Lodash
_.intersection([2, 1, 2], [2, 3]);
// → [2]
Try It Yourself

How It Works

  1. First 2. Shared with the second array → kept.
  2. 1. Not in the second array → skipped.
  3. Second 2. Already emitted → skipped (uniqueness).
  4. Docs. Result values are unique by design.

Example 5 — Order Follows the First Array

Swap which array comes first and the order can change.

Lodash
_.intersection([3, 1, 2], [1, 2, 3]);
// → [3, 1, 2]

_.intersection([1, 2, 3], [3, 1, 2]);
// → [1, 2, 3]
Try It Yourself

How It Works

  1. Same set. Both calls share 1, 2, and 3.
  2. First call. Order matches [3, 1, 2].
  3. Second call. Order matches [1, 2, 3].
  4. Tip. Put the array whose order you care about first.

Browser & Runtime Support

_.intersection is a Lodash 4.x Array helper (available since early Lodash). It runs anywhere Lodash runs — modern browsers (via CDN or bundle) and Node.js / Bun / Deno with npm install lodash.

✓ Stable · Lodash 4.x

_.intersection()

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

100% With Lodash 4.x
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
_.intersection Lodash 4.x+

Bottom line: Safe for production once Lodash is on the page or in your bundle. Prefer import intersection from "lodash/intersection" for smaller builds. Native Set intersection patterns exist in modern JS but differ in API shape.

Frequently Asked Questions

_.intersection(...arrays) returns a new array of unique values that appear in every given array, using SameValueZero equality. Order and object references follow the first array.
No. It returns a new array. Each argument array stays unchanged.
The first array. Values are listed in the order they first appear there, if they also exist in every other array.
difference removes values found in the other lists. intersection keeps only values present in all lists.
Use _.intersectionBy when equality should run on a projected key (like a property). Use _.intersectionWith for a custom comparator function.
Use import intersection from "lodash/intersection" or require("lodash/intersection") for tree-shaking friendly bundles. Full build: import _ from "lodash" then _.intersection.

Next: _.intersectionBy()

Intersect arrays by projecting each element with an iteratee first.

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