Breadcrumbs

Get Array Element Operator []

Returns an array element.

Syntax

anArray[anIndex]

Semantics

The operator [i] returns the i-th element of the array.

The first element has the position 0.

anIndex can be a static integer literal, an object of type Integer, or an action script language or expression returning an integer.

Substitutables

anArray

Can be any variable or object attribute having the type Array

anIndex

Can be any expression that evaluates to an integer.

It is not possible to use class operations as index function – only built-in action script language operations are allowed.

Examples

Get a specific array element

Input: an array of names

JSON
{"names": ["Irene", "Eliza", "Raymond", "Jane", "David"]}
set name = names[1];

Result: name is Eliza.

Get the last array element

Input: an array of names

JSON
{"names": ["Irene", "Eliza", "Raymond", "Jane", "David"]}
set name = names[names.count()-1];

Result: name is David.

Get a property from a complex array element

Input: a list of articles

JSON
{ "articles": [
    {"name": "AF-1200", "price": 64.50},
    {"name": "AF-1400", "price": 72.50},
    {"name": "CD-2002", "price": 570.00}
]}
set price = articles[0].price;

Result: price is 64.50.

📗

Related Pages: