I have an array of objects which uses a delimited string as the keys. When examined in the FB4 debugger, the keys look like this:
[+] 22477◦25220◦20.1 [+] 22477◦25220◦20.6 [+] 22477◦25220◦20.8 [+] 22477◦25244◦55.1K(j)
The first two items are numeric (cast to string) but the third item in the multi-part delimited key is naturally a string — it’s like an alphanumeric library shelf reference. As expected, when you click on the [+] icon in the debugger, you can view the object associated with that string key. So far so good.
The debugger shows the keys in the (pre-sorted) order in which they were added to the array. However, when iterating the object array so:
for (var key: String in MyAssociativeArray){
// keys are visited not in the order displayed by the debugger
}
the keys are returned in some other order –internal hash? My question is, how does the debugger know the order the keys were added in, and can I access that knowledge at runtime when iterating the array? I want to iterate the objects in the order in which they were added. Or do I need to maintain my own index of these keys showing the order they were added to the associative array?
[0] 22477◦25220◦20.1 [1] 22477◦25220◦20.6 [2] 22477◦25220◦20.8 [3] 22477◦25244◦55.1K(j)
Thanks
The debugger sorts lists of items in an associative array lexicographically for you (ordered numerically and alphabetically) to make it easier to find what you’re looking for. The list in your example is sorted this way. It’s a coincidence that you added items to the associative array in the same order.
There is no way for you to discover the order in which you add items to an associative array without creating additional metadata. If you need such behavior try creating a custom class for this.
Here’s an example:
With the above you can do something like this: