Copy as Markdown[Open in ChatGPT](https://chatgpt.com/?q=Read%20https%3A%2F%2Fdocs-docusaurus.kinsta.page%2Fdataprime%2Flanguage-reference%2Ffunctions-reference%2Farray%2Fsetintersection.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)[Open in Claude](https://claude.ai/new?q=Read%20https%3A%2F%2Fdocs-docusaurus.kinsta.page%2Fdataprime%2Flanguage-reference%2Ffunctions-reference%2Farray%2Fsetintersection.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)

# `setIntersection`

## Description

Returns the intersection of two arrays, producing a new array with elements common to both.

* Both arrays are treated as sets:

- Duplicates are removed from both arrays
- Order is not preserved in the result
- `null` is treated as an empty set
- Supported element types include `string`, `bool`, `number`, `interval`, `timestamp`, `regexp`, and `enum`.

## Syntax

Like many functions in DataPrime, `setIntersection` supports<!-- --> [two notations](https://docs-docusaurus.kinsta.page/dataprime/language-reference/functions-reference/.md),<!-- --> **function** and **method**. These interchangeable forms allow flexibility in how you structure expressions.

* Function notation
* Method notation

```
setIntersection(array1: array<T>, array2: array<T>): array<T>
```

```
(array1: array<T>).setIntersection(array2: array<T>): array<T>
```

## Arguments

| Name     | Type       | Required | Description                 |
| -------- | ---------- | -------- | --------------------------- |
| `array1` | `array<T>` | **true** | The first array to compare  |
| `array2` | `array<T>` | **true** | The second array to compare |

## Example

**Use case: Compare observed IPs against a block list**

Suppose you collect IP addresses accessing different paths. Consider the following input:

```
{

    "path": "/home",

    "ip_addresses": ["156.76.87.4", "156.76.12.4", "156.74.1.4"]

},

{

    "path": "/checkout",

    "ip_addresses": ["156.76.87.4"]

}
```

By applying `setIntersection`, you can identify which observed IP addresses also appear in a known block list.

### Example query

* Function notation
* Method notation

```
create unauthorized_ip_addresses from setIntersection(ip_addresses, ["156.76.12.4", "156.76.87.4"])
```

```
create unauthorized_ip_addresses from ip_addresses.setIntersection(["156.76.12.4", "156.76.87.4"])
```

### Example output

The result will include a new field `unauthorized_ip_addresses` showing IPs found in both arrays:

```
{

    "path": "/home",

    "ip_addresses": ["156.76.87.4", "156.76.12.4", "156.74.1.4"],

    "unauthorized_ip_addresses": ["156.76.87.4", "156.76.12.4"]

},

{

    "path": "/checkout",

    "ip_addresses": ["156.76.87.4"],

    "unauthorized_ip_addresses": []

}
```
