Last updated on: February 06, 2021
Also available as a single HTML file
Variables can store a single value or a set of values. Variables that store a set of values are of Array data type. Arrays can store an unbounded amount of <key, value> pairs. The values are always accessed by providing the key (known as index). New elements can be added to arrays by assignment and specifying the a key that doesn't exist in the array:
$Names = "Fred" $Names = "Kate" $Names = "Sally"
Arrays can also be created by Array function by simply providing the list of elements:
$Names = Array("Fred", "Kate", "Sally")
Here the indices are autmatically assigned as 0, 1, 2
Iterating over Array Elements
Values in the array can be iterated over using ForEach statements
ForEach ($Name in $Names) InsertObject($Outline, "Paragraph", -1).text = $Name
There are a several functions that generate and consume arrays. QueryObjects and QueryText functions return arrays of objects. String_Split function splits a given string into an array of strings, while Array_Join function reverses this. Array_Length function will return the number of elements in an array.
Using an array as a stack or a queue
Array_PopFront and Array_PushBack functions can be used as equivalents of dequeue and enqueue operations on a queue data structure. Similarly Array_PushBack and Array_PopBack functions allow an array to be used as a stack, providing simple push/pop functionality. Finally there is an Array_PushFront function to insert an element at the beginning of an array.
Arrays can be multi-dimensional if they contain other arrays:
$Names = Array(Array("Fred", "Williams"), Array("Kate", "Smith"), Array("Sally", "Jones")) $SallysLastName = $Names