Underscore.js _.intersection() Method

Beginner
5 min read
Updated: Nov 2026
4 examples
Array

Definition

Computes the list of values that are the intersection of all the arrays — each value in the result is present in each of the arrays (official Underscore docs). Stable Array helper — not deprecated.

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

Syntax

Call _.intersection. Start with this line.

Underscore
_.intersection(*arrays)
CallWhat it does
_.intersection(*arrays)Primary signature.
_.intersection(...)Call with the arguments your case needs.

Load Underscore with import _ from "underscore" (or the UMD CDN build) so these helpers are available as _.

Library declarations
Underscore
_.intersection(*arrays)

Parameters

ParameterDescription
*arraysRequired. Lists to compare; first sets result order

Return Value

Return ValueDescription
*New unique array of shared values

Underscore.js Examples

Example 1 — Official: Three Arrays

Keep values that appear in every list.

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

How It Works

  1. Start from the first array. Candidates are 1, 2, 3.
  2. Require membership in all others. 1 and 2 pass; 3 does not.
  3. Ignore extras. 101 and 10 are never candidates.
  4. Result order. Follows the first array: [1, 2].

Example 2 — Two Arrays

The simplest overlap — shared values between a pair of lists.

Underscore
_.intersection(["a", "b", "c", "d"], ["c", "a", "e"]);
// → ["a", "c"]
Try It Yourself

How It Works

  1. Walk the first list. a and c exist in the second.
  2. Drop the rest. b and d are not shared.
  3. Skip second-only values. e is not a candidate.
  4. Order. a before c because that is first-array order.

Example 3 — First-Array Order & Uniqueness

Duplicates collapse; order still follows the first array.

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

How It Works

  1. First hit for 2. Shared → keep once.
  2. Then 1. Also shared → keep.
  3. Second 2. Already in the result → skipped.
  4. 3. Missing from others → dropped.

Example 4 — Empty Arrays & No Overlap

Empty lists and disjoint lists both yield an empty result.

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

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

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

How It Works

  1. Empty other. Nothing can be in every array → [].
  2. No shared values. Same outcome → [].
  3. Single array. Intersection with itself is a unique copy of that list.
  4. Safe. Never throws on empty inputs.

Browser & Runtime Support

_.intersection ships with Underscore.js (1.x). It runs anywhere Underscore runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install underscore.

✓ Stable · Underscore 1.x

_.intersection()

Available in [email protected] (UMD / ESM). Works in evergreen browsers and current Node LTS when Underscore is loaded.

100% With Underscore 1.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 Underscore 1.x+

Bottom line: Safe for production once Underscore is on the page or in your bundle. Not a native browser API — load Underscore first. Prefer a pinned CDN version (e.g. [email protected]).

Frequently Asked Questions

_.intersection(*arrays) returns values that appear in every array you pass. Official example: _.intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]) → [1, 2].
As many as you like. It is variadic: _.intersection(a, b, c).
Yes. Each shared value appears only once in the result, even if it repeats in the inputs.
The order of the first array — each value keeps the position of its first appearance there.
With strict equality (===). Primitives match by value; objects and arrays match by reference.
_.union keeps values from any array (combine). _.intersection keeps only values in all arrays (overlap).

Next: _.difference()

Return values from the first array that are not present in the others.

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