# Find the intersection of arrays

Return the distinct values that occur in both arrays.

Canonical: https://1loc.dev/array/get-the-intersection-of-arrays/
Version: 1.0.0
Runtime: JavaScript · Node.js 22 / modern browsers
Verification: Local fixtures; no external services
Updated: 2026-10-28

## Implementation

```javascript
function intersection({ left, right }) { const other = new Set(right); return [...new Set(left)].filter(value => other.has(value)); }
```

## Input

```json
{
  "left": [
    "ana@example.com",
    "rui@example.com",
    "lia@example.com"
  ],
  "right": [
    "rui@example.com",
    "old@example.com"
  ]
}
```

## Expected output

```json
[
  "rui@example.com"
]
```

## Edge case

Input:
```json
{
  "left": [],
  "right": [
    1
  ]
}
```
Output:
```json
[]
```

## Limits

- Result order follows the first array. Duplicate results are removed.
- Objects are compared by identity, not by their properties.
- Example: recipients that are also on a suppression list. Compare normalized addresses, and treat the provider’s suppression state as the authority.

The lab validates types and size before calling this function. Add equivalent validation at your own trust boundary.

## Source and license

Original: https://github.com/phuocng/1loc/blob/14b481cf60dff1620ab1bb99a43b1f68068cdd9b/contents/get-the-intersection-of-arrays.mdx
Author: Nguyen Huu Phuoc and original contributors
Contributors: vreymond, robinpokorny
Source commit: 14b481cf60dff1620ab1bb99a43b1f68068cdd9b
Copyright (c) 2020 phuoc-ng
License: MIT — https://1loc.dev/licenses/
Maintainer: Oveyon
Modifications: Curated implementation; explicit input bounds, edge cases, local fixtures and rebuilt presentation. Original MDX retained as inert source evidence.
