I’m having trouble with a script where I need to loop through an array and display its contents. My goal is to create a list from the array values and set it in a field. However, the field is only displaying the first value of the array, not iterating through the rest.
Code: Select all
-- Define and populate the array
put "Apple" into tArray["fruit1"]
put "Banana" into tArray["fruit2"]
put "Cherry" into tArray["fruit3"]
-- Initialize the field
put "" into fld "fruitList"
-- Loop through the array and display values
repeat for each key tKey in tArray
put tArray[tKey] & cr after fld "fruitList"
end repeat
Is there something wrong with the way I’m using the `repeat for each` loop to iterate through the array?
How can I ensure all values in the array are displayed in the field?