You could just use Array#reduce with Array#filter and Array#includes.

var array1 = ["Lorem", "ipsum", "dolor"],
    array2 = ["Lorem", "ipsum", "quick", "brown", "foo"],
    array3 = ["Jumps", "Over", "Lazy", "Lorem"],
    array4 = [1337, 420, 666, "Lorem"],
    data = [array1, array2, array3, array4],
    result = data.reduce((a, b) => a.filter(c => b.includes(c)));

console.log(result);

Answer from Nina Scholz on Stack Overflow
Top answer
1 of 16
1960

Use a combination of Array.prototype.filter and Array.prototype.includes:

const filteredArray = array1.filter(value => array2.includes(value));

For older browsers, with Array.prototype.indexOf and without an arrow function:

var filteredArray = array1.filter(function(n) {
    return array2.indexOf(n) !== -1;
});

NB! Both .includes and .indexOf internally compares elements in the array by using ===, so if the array contains objects it will only compare object references (not their content). If you want to specify your own comparison logic, use Array.prototype.some instead.

2 of 16
163

Destructive seems simplest, especially if we can assume the input is sorted:

/* destructively finds the intersection of 
 * two arrays in a simple fashion.  
 *
 * PARAMS
 *  a - first array, must already be sorted
 *  b - second array, must already be sorted
 *
 * NOTES
 *  State of input arrays is undefined when
 *  the function returns.  They should be 
 *  (prolly) be dumped.
 *
 *  Should have O(n) operations, where n is 
 *    n = MIN(a.length, b.length)
 */
function intersection_destructive(a, b)
{
  var result = [];
  while( a.length > 0 && b.length > 0 )
  {  
     if      (a[0] < b[0] ){ a.shift(); }
     else if (a[0] > b[0] ){ b.shift(); }
     else /* they're equal */
     {
       result.push(a.shift());
       b.shift();
     }
  }

  return result;
}

Non-destructive has to be a hair more complicated, since we’ve got to track indices:

/* finds the intersection of 
 * two arrays in a simple fashion.  
 *
 * PARAMS
 *  a - first array, must already be sorted
 *  b - second array, must already be sorted
 *
 * NOTES
 *
 *  Should have O(n) operations, where n is 
 *    n = MIN(a.length(), b.length())
 */
function intersect_safe(a, b)
{
  var ai=0, bi=0;
  var result = [];

  while( ai < a.length && bi < b.length )
  {
     if      (a[ai] < b[bi] ){ ai++; }
     else if (a[ai] > b[bi] ){ bi++; }
     else /* they're equal */
     {
       result.push(a[ai]);
       ai++;
       bi++;
     }
  }

  return result;
}
Discussions

Compute intersection of two arrays in JavaScript - Stack Overflow
Reading this made me start thinking.. what should the expected result of an intersection be if you have "sue" appearing multiple times in one/both of the arrays? More on stackoverflow.com
🌐 stackoverflow.com
Multiple array intersection in javascript - Stack Overflow
How to write in javascript(w/wth JQuery) to find values that intersect between arrays? More on stackoverflow.com
🌐 stackoverflow.com
May 24, 2017
javascript - Finding intersection in multiple arrays - Stack Overflow
I have tried to build on this answer: Multiple array intersection in javascript but I could not figure it out, as it uses static variables (a,b,c) for the example. More on stackoverflow.com
🌐 stackoverflow.com
How to calculate the intersection of multiple arrays in JavaScript
You skip over the interesting part of object comparisons (comparing the objects) entirely by going for a "key" property (without explaining why), and go directly to code (with, I think, at least one bug) instead of explaining concepts. I think this would be a better and more useful read if you included more background, theory, and practical comparisons (beyond just the order of elements). More on reddit.com
🌐 r/javascript
12
23
March 15, 2023
🌐
Reddit
reddit.com › r/javascript › how to calculate the intersection of multiple arrays in javascript
r/javascript on Reddit: How to calculate the intersection of multiple arrays in JavaScript
March 15, 2023 - function intersect(...arrays) { return arrays?.reduce((intersection, currentArray) => { const intersectionSet = new Set(intersection); return currentArray.filter((item) => intersectionSet.has(item)); }); } ... using spread operator instead of keyword arguments makes your function easier to use as people will know what is expected as arguments · YOUR MULTIPLE ARRAY EXAMPLE IS WRONG as it does not return an empty array if first array is empty.
🌐
Programiz
programiz.com › javascript › examples › intersection-two-arrays
JavaScript Program To Perform Intersection Between Two Arrays
To understand this example, you should have the knowledge of the following JavaScript programming topics: ... // program to perform intersection between two arrays using Set // intersection contains the elements of array1 that are also in array2 function performIntersection(arr1, arr2) { // converting into Set const setA = new Set(arr1); const setB = new Set(arr2); let intersectionResult = []; for (let i of setB) { if (setA.has(i)) { intersectionResult.push(i); } } return intersectionResult; } const array1 = [1, 2, 3, 5, 9]; const array2 = [1, 3, 5, 8]; const result = performIntersection(array1, array2); console.log(result);
🌐
Vultr Docs
docs.vultr.com › javascript › examples › perform-intersection-between-two-arrays
JavaScript Program to Perform Intersection Between Two Arrays | Vultr Docs
December 18, 2024 - This code snippet creates two arrays and filters array1 to include only the elements that are also present in array2, resulting in an intersection of [4, 5]. The filter() method iterates through each item of array1, and the includes() method checks if that item exists in array2.
🌐
4Geeks
4geeks.com › how-to › javascript-array-intersection
How to find the interception of Arrays in Javascript?
July 16, 2025 - Learn how to find the intersection of two or more arrays in Javascript. Discover different methods for finding common elements and optimizing your code.
Find elsewhere
🌐
Medium
medium.com › @alvaro.saburido › set-theory-for-arrays-in-es6-eb2f20a61848
Array intersection, difference, and union in ES6 | by Alvaro Saburido | Medium
August 2, 2020 - The intersection will give us the elements that both arrays share in common, in this case, the result must be [1,5].
🌐
Stack Overflow
stackoverflow.com › questions › 41971051 › multiple-array-intersection-in-javascript
Multiple array intersection in javascript - Stack Overflow
May 24, 2017 - what it does is it checks for each element in array 'a' and checks if that value is present in array 'b' and array 'c'. If it is true it returns the value. Simple!!!. The above code should work for String as well but it wouldn't work for IE ...
🌐
TutorialsPoint
tutorialspoint.com › article › simplest-code-for-array-intersection-in-javascript
Simplest code for array intersection in JavaScript?
March 15, 2026 - var arrays = [ [1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5, 6] ]; var intersection = arrays.reduce((acc, current) => acc.filter(x => current.includes(x))); console.log("Multiple arrays intersection:", intersection);
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-create-an-array-using-intersection-of-two-arrays-in-javascript
How to Create an Array using Intersection of two Arrays in JavaScript ? | GeeksforGeeks
If the array is already sorted, ... In JavaScript, finding the union of multiple arrays means combining their elements into a single array with only unique values....
Published: May 21, 2024
🌐
GitHub
gist.github.com › lovasoa › 3361645
Compute the intersection of large arrays in javascript · GitHub
It is also published on npm: fast_array_intersect · The compressed version is only 345 caracters long. Faster than common libraries, even a large number of arrays, or on very big arrays. (See benchmarks) ... The idea is simple and comes from here: http://pioupioum.fr/developpement/javascript-array-intersection.html.
🌐
Bobby Hadz
bobbyhadz.com › blog › javascript-get-intersection-of-two-arrays
Get the Intersection of two Arrays or Sets in JavaScript | bobbyhadz
The Array.reduce() method returns ... use the lodash library. Install the lodash library. ... Use the intersection() method to get the intersection of two or more arrays....
🌐
xjavascript
xjavascript.com › blog › simplest-code-for-array-intersection-in-javascript
How to Find Array Intersection in JavaScript: Simplest Library-Free Code Example — xjavascript.com
Multiple arrays: Use reduce() to iteratively compute intersections. Choose the method based on your use case (array size, duplicates, etc.).
🌐
Medium
medium.com › @stheodorejohn › finding-the-intersection-of-two-arrays-in-javascript-8bd54c5c9c08
Finding the Intersection of Two Arrays in JavaScript | by Theodore John.S | Medium
June 23, 2023 - Approach 1: Using Built-in Functions We can utilize JavaScript’s built-in functions to solve this problem efficiently. The filter function can be used to iterate over one array and return the elements that exist in the second array.
🌐
GitHub
github.com › lovasoa › fast_array_intersect
GitHub - lovasoa/fast_array_intersect: The fastest javascript array intersection function · GitHub
fast_array_intersect x 1,064,622 ops/sec ±0.55% (92 runs sampled) intersect x 360,324 ops/sec ±0.46% (95 runs sampled) intersection-of x 303,913 ops/sec ±0.35% (97 runs sampled) array-intersection-x x 28,616 ops/sec ±0.20% (94 runs sampled) Fastest is fast_array_intersect 2 arrays of 100 elements, with an intersection of size 10...
Author: lovasoa
🌐
Techie Delight
techiedelight.com › home › java › find intersection of two arrays in javascript
Find intersection of two arrays in JavaScript | Techie Delight
July 7, 2026 - Another solution is to convert the array into an ES6 Set and call its has() method to check for the other array elements.
🌐
TutorialsPoint
tutorialspoint.com › how-to-create-an-array-using-intersection-of-two-arrays-in-javascript
Intersection of two arrays JavaScript
February 23, 2023 - When found, we add it to the result and remove it from the larger array to handle duplicates correctly. const arr1 = [1, 2, 43, 5, 3, 7, 7, 8, 4, 2]; const arr2 = [1, 1, 6, 6, 2, 78, 7, 2, 3, 7, 23, 5, 3]; const intersection = (arr1, arr2) => { const res = []; const { length: len1 } = arr1; const { length: len2 } = arr2; const smaller = (len1 < len2 ?
🌐
YouTube
youtube.com › watch
JavaScript Tutorial: Find Intersection of Two Arrays Easily | Find Common Values in Two Arrays - YouTube
📌 Topics Covered:What is array intersection in JavaScriptMultiple methods to find common elementsTips for optimizing your codeIn this JavaScript tutorial, l...
Published: November 11, 2024