An array lets you store one or more values in a single value as a series of elements. Every element in the array must have a key that identify it. This can be a string or a number.

put "apple" into myArray[1]
put "orange" into myArray[2]
put "grape" into myArray[3]
put "lemon" into myArray[fruit]
put myArray[2] // outputs orange
put myArray[lemon] // outputs lemon

You can empty an element in an array (the element / key still exist, it just wont contain a value):

put empty into myArray[fruit]

You can delete an element and its key out of an array:

delete variable myArray[fruit]

You can delete an array (remove all keys and values)

put empty into myArray

You can get the list of the keys of an array

put the keys of myArray

Multidimensional Arrays

LiveCode supports multidimensional arrays,

inside an array element, you are storing an array of values
put "Simon" into myArray[1][firstname]
put "Smith" into myArray[1][surname]
put "Mr" into myArray[1][title]
put "Tracy" into myArray[2][firstname]
put "Smith" into myArray[2][surname]
put "Mrs" into myArray[2][title]
put "Hayley" into myArray[3][firstname]
put "Smith" into myArray[3][surname]
put "Miss" into myArray[3][title]
put myArray[2][firstname] // outputs tracy

arrayEncode and arrayDecode

arrayEncode converts an array into a string that can be saved or transmitted. Use arrayDecode to convert the string back to an array.

put arrayEncode(myArray) into mySavedVar

Converting a string into an array

LiveCode can convert a string into an array using the split function

put "red,green,blue" into myArrayToBe
split myArrayToBe by comma // myArrayToBe is nolonger a string, its an array

a more detailed explanation of the split function is on its way.

Checking if an array is empty

put LetterFrequencyCounts(myText) into frequencyArray
if the keys of myArray is not empty then
 -- statements
end if

Getting the last element of an array

put myArray[last line of the keys of myArray]
Contact Us

We're not around right now. But you can send us an email and we'll get back to you, asap.

Not readable? Change text. captcha txt

Start typing and press Enter to search