> For the complete documentation index, see [llms.txt](https://docs.datajet-app.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.datajet-app.com/liquid/filters/flat.md).

# flat

Flattens a nested array by a specified depth level. Useful when working with arrays of arrays, such as results from `map` on nested data.

```liquid
{% assign all_tags = products | map: "tags" | flat %}
{% log all_tags %}
```

#### Syntax

```liquid
{{ array | flat }}
{{ array | flat: depth }}
```

| Parameter | Description                                          |
| --------- | ---------------------------------------------------- |
| `array`   | Array to flatten                                     |
| `depth`   | How many levels of nesting to flatten (default: `1`) |

#### Return Value

Returns a new array with nested arrays flattened to the specified depth.

#### Examples

**Flatten one level (default):**

```liquid
{% assign nested = "1,2|3,4|5,6" | split: "|" | map: "split", "," %}
{% assign flattened = nested | flat %}
{% log flattened %}
```

**Collect all tags from multiple products:**

```liquid
{% assign all_tags = products | map: "tags" | flat %}
{% assign unique_tags = all_tags | uniq %}
{% log unique_tags %}
```

**Flatten deeply nested arrays:**

```liquid
{% assign deep_flat = nested_array | flat: 2 %}
{% log deep_flat %}
```

**Collect all variant SKUs across products:**

```liquid
{% assign all_variants = products | map: "variants" | flat %}
{% assign all_skus = all_variants | map: "sku" %}
{% log all_skus %}
```

#### Notes

* Default depth is `1` — only the first level of nesting is flattened
* Non-array values are wrapped in an array before flattening
* Use higher depth values for deeply nested structures
