Name: []

Type: keyword

Syntax: []

Summary: The square bracket characters [ ] surround the <element> name in an <array> reference.

Introduced: 1.0

OS: mac,windows,linux,ios,android

Platforms: desktop,server,web,mobile

Example:
put thisValue into myArray["someKey"]

Example:
if myArray["someOtherKey"] is "A" then beep

Description:
Use square brackets [ ] to specify which <element> in an <array> you are referring to.

You access an element of an array by using the name of the array, along with the key in square brackets:

  put "A" into myList["firstLetter"]
  put "B" into myList["secondLetter"]
  put "C" into myList["thirdLetter"]
  get myList["secondLetter"] -- yields "B"

Square brackets must be used in pairs, each [ with a matching ]. Using a single square bracket does not cause an <error>, but the bracket is interpreted as part of the <variable> name, rather than as the marker for the <key> of an <array> reference.

>*Note:* Arrays in LiveCode are associative (also known as hash tables). This means that when an array element is accessed using square bracket notation, the value in between the brackets is used to "look up" the element, and is not a numeric index as in C, Pascal and other languages. Of course it is still possible to use numbers as array keys, but LiveCode internally converts these to strings before retrieving the array elements.

References: element (keyword), () (operator), split (command), arrayEncode (function), array (glossary), variable (glossary), error (glossary), key (glossary)

Tags: properties
