---
title: "Arrays"
description: "Ordered key-value collections in iXML — the primary complex data structure."
canonical_url: "https://www.zeyos.com/ixml/ixml-guide/data-types/arrays"
markdown_url: "https://www.zeyos.com/ai/guide/ixml/ixml-guide/data-types/arrays.md"
section: "ixml-guide"
authority: "guide"
language: "en"
source_repository: "zeyos/guide"
source_path: "docs/ixml/02-data-types/arrays/index.md"
source_revision: "cce886a8da98cd124ee3644711085bbdcf1a87ce"
---

# Arrays

The **Array** type (`array`) is the primary complex data structure in iXML. It is an ordered map that associates keys to values.

- **typeof result**: `'array'`
- **Assignment**: Assigned by **reference** (not copied on assignment)

## Key features

- **Associative**: Keys can be strings (`array.key`) or integers (`array[0]`).
- **Ordered**: Iteration order is preserved.
- **Nested**: Arrays can contain other arrays, enabling complex data structures.

## Creating arrays

```xml
<!-- Inline construction -->
<array var="colors">
    <item>red</item>
    <item>green</item>
    <item>blue</item>
</array>

<!-- Incremental construction -->
<set var="person.name">John</set>
<set var="person.age">30</set>
```

[`array`](https://www.zeyos.com/ixml/ref/array)

## By-reference behavior

Arrays are assigned by reference. When you assign an array to another variable, both variables point to the same data:

```xml
<array var="original">
    <item key="a">1</item>
</array>
<assign var="copy" var_source="original" />
<set var="copy.a">changed</set>
<output>$original.a</output>
<!-- changed -->
```

Use [`clone`](https://www.zeyos.com/ixml/ref/clone) if you need an independent copy:

```xml
<clone var="independent" var_source="original" />
```

## Accessing array items

Use dot notation for known keys and bracket notation for dynamic keys:

```xml
<output>$person.name</output>        <!-- dot notation -->
<output>$person[name]</output>       <!-- bracket notation -->

<set var="key">name</set>
<output>$person[$key]</output>       <!-- dynamic key -->
```

See [Variables and Substitution](https://www.zeyos.com/ixml/ixml-guide/introduction/variables-and-substitution) for the full key chain syntax.

:::warning Destructive operations
Many array commands in iXML are **destructive by default** — they modify the source array in-place. Commands that support a `var_result` attribute let you opt into non-destructive behavior.
:::

## In this chapter

- **[Construction](https://www.zeyos.com/ixml/ixml-guide/data-types/arrays/construction)** — `array`, `item`, `array:range`, `array:assoc`, `array:populate`
- **[Inspection](https://www.zeyos.com/ixml/ixml-guide/data-types/arrays/inspection)** — `array:length`, `array:keyexists`, `array:valueexists`, `array:pos`, `array:first`, `array:last`, `array:rand`
- **[Stack and Queue](https://www.zeyos.com/ixml/ixml-guide/data-types/arrays/stack-queue)** — `array:push`, `array:pop`, `array:shift`, `array:unshift`
- **[Slicing and Restructuring](https://www.zeyos.com/ixml/ixml-guide/data-types/arrays/slicing)** — `array:concat`, `array:slice`, `array:extract`, `array:pad`, `array:reverse`, `array:flip`, `array:chunk`
- **[Set Operations](https://www.zeyos.com/ixml/ixml-guide/data-types/arrays/set-operations)** — `array:merge`, `array:unique`, `array:diff`, `array:intersect`, `array:union`
- **[Filtering and Sorting](https://www.zeyos.com/ixml/ixml-guide/data-types/arrays/filtering-sorting)** — `array:filter`, `array:keys`, `array:values`, `array:sort`
