Skip to main content

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

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 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 for the full key chain syntax.

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

  • Constructionarray, item, array:range, array:assoc, array:populate
  • Inspectionarray:length, array:keyexists, array:valueexists, array:pos, array:first, array:last, array:rand
  • Stack and Queuearray:push, array:pop, array:shift, array:unshift
  • Slicing and Restructuringarray:concat, array:slice, array:extract, array:pad, array:reverse, array:flip, array:chunk
  • Set Operationsarray:merge, array:unique, array:diff, array:intersect, array:union
  • Filtering and Sortingarray:filter, array:keys, array:values, array:sort