Copy as Markdown[Open in ChatGPT](https://chatgpt.com/?q=Read%20https%3A%2F%2Fdocs-docusaurus.kinsta.page%2Fdataprime%2Flanguage-reference%2Ffunctions-reference%2Farray%2Fsetdiffsymmetric.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%2Fsetdiffsymmetric.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)

# `setDiffSymmetric`

## Description

Returns the symmetric difference of two arrays, producing a new array with elements that exist in either `array1` or `array2` but not in both.

* Duplicates are discarded when computing the difference.
* Supported element types include `string`, `bool`, `number`, `interval`, `timestamp`, `regexp`, and `enum`.

## Syntax

Like many functions in DataPrime, `setDiffSymmetric` 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

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

```
(array1: array<T>).setDiffSymmetric(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: Identify differences between two IP allow lists**

Suppose you maintain two separate allow lists of IP addresses. Consider the following input:

```
{

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

    "ip_addresses_b": ["156.76.87.4", "156.76.1.4"]

}
```

By applying `setDiffSymmetric`, you can find IPs that exist in one list but not the other.

### Example query

* Function notation
* Method notation

```
create diff_ips from setDiffSymmetric(ip_addresses_a, ip_addresses_b)
```

```
create diff_ips from ip_addresses_a.setDiffSymmetric(ip_addresses_b)
```

### Example output

The result will include a new field `diff_ips` showing only the differing elements:

```
{

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

    "ip_addresses_b": ["156.76.87.4", "156.76.1.4"],

    "diff_ips": ["156.76.12.4", "156.74.1.4", "156.76.1.4"]

}
```
