Reputation: 155
var personTab:Object=new Object()
personTab.firstName='John'
personTab.lastName='Appleseed'
personTab.age=18
for(var A:String in personTab)
{
trace(A+': '+personTab[A])
}
Output order is lastName, firstName, age. What I don't understand is why it's not firstName, lastName, age. Also, if i change the name of the variable 'A' to say 'foo' the order changes to firstName, age, lastName.
Upvotes: 2
Views: 62
Reputation: 12431
Objects in ActionScript are unordered, essentially you can think of them as a hash-table or associative array in which the values are referenced by their key (see documentation). If the order is important to you you should use an array or, if you also need the ability to look-up values by key, create your own custom collection which preserves the order.
Upvotes: 2