# array\_difference

Returns elements that exist in the first array but not in the second array. Similar to set subtraction (A - B).

```liquid
{% assign all_skus = "SKU1,SKU2,SKU3,SKU4,SKU5" | split: "," %}
{% assign processed_skus = "SKU2,SKU4" | split: "," %}

{% assign remaining = all_skus | array_difference: processed_skus %}
```

Output:

```
SKU1, SKU3, SKU5
```

#### Syntax

```liquid
{{ arrayA | array_difference: arrayB }}
```

| Parameter | Description                  |
| --------- | ---------------------------- |
| `arrayA`  | Source array                 |
| `arrayB`  | Array of elements to exclude |

#### Visual Representation

```
Array A: [1, 2, 3, 4, 5]
Array B: [3, 4, 5, 6, 7]

Result:  [1, 2]  (elements in A that are NOT in B)
```

#### Examples

**Find products not yet synced:**

```liquid
{% assign all_product_ids = shopify_products | map: "id" %}
{% assign synced_product_ids = sync_log | map: "product_id" %}

{% assign unsynced_ids = all_product_ids | array_difference: synced_product_ids %}

{% log "Products not yet synced: " | append: unsynced_ids.size %}

{% for product_id in unsynced_ids %}
  {% comment %} Sync this product {% endcomment %}
{% endfor %}
```

**Find removed tags:**

```liquid
{% assign old_tags = "sale,featured,new,bestseller" | split: "," %}
{% assign new_tags = "featured,bestseller" | split: "," %}

{% assign removed_tags = old_tags | array_difference: new_tags %}
{% log "Tags removed: " | append: removed_tags | join: ", " %}
```

Output:

```
Tags removed: sale, new
```

**Identify discontinued SKUs:**

```liquid
{% assign current_catalog_skus = current_products | map: "sku" %}
{% assign new_catalog_skus = import_data | map: "sku" %}

{% assign discontinued = current_catalog_skus | array_difference: new_catalog_skus %}

{% if discontinued.size > 0 %}
  {% log "Discontinued SKUs:" %}
  {% log discontinued %}

  {% for sku in discontinued %}
    {% comment %} Archive or mark as discontinued {% endcomment %}
  {% endfor %}
{% endif %}
```

**Filter out excluded customers:**

```liquid
{% assign all_customer_ids = customers | map: "id" %}
{% assign vip_customer_ids = vip_list | map: "customer_id" %}

{% assign non_vip_ids = all_customer_ids | array_difference: vip_customer_ids %}

{% log "Regular customers: " | append: non_vip_ids.size %}
{% log "VIP customers: " | append: vip_customer_ids.size %}
```

**Find orders missing from fulfillment report:**

```liquid
{% assign all_order_names = orders | map: "name" %}
{% assign fulfilled_order_names = fulfillment_report | map: "order_name" %}

{% assign unfulfilled = all_order_names | array_difference: fulfilled_order_names %}

{% if unfulfilled.size > 0 %}
  {% log "Orders not in fulfillment report:" %}
  {% for order_name in unfulfilled %}
    {% log order_name %}
  {% endfor %}
{% endif %}
```

#### Notes

* Both inputs must be arrays; throws error otherwise
* Preserves order of elements from the first array
* Duplicate elements in arrayA are preserved if they don't exist in arrayB
* Returns empty array if all elements of arrayA exist in arrayB
* Comparison uses strict equality (===)
* See also: `array_intersection`, `array_symmetric_difference`


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.datajet-app.com/liquid/filters/array_difference.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
