I am looking for the equivalent of a foreach loop with keys in ActionScript. In PHP, it will be:
foreach($array as $key => $value)
{
}
I found two solutions that will work, but I am wondering if there is a better way to do this. The first solution is to use a for..in loop. Which gives you the keys, but you should still use the key to access the correct element in your structure. For example:
for(var key:String in results)
{
trace(key + ": " + results[key]);
}
The second option is for each cycle ... which, in my opinion, is new in AS3. With this solution, I can’t say what the keys are. For example:
for each(var row:* in results)
{
trace(row);
}
So far, I'm going to use for .... I'm just looking for a better way.
Thanks Rob
: , . , . :
sites = {'site1': 34, 'site2': 52, 'site3': 66}
, .
, . , :
sites = {{'name': 'site1', 'id': 34},
{'name': 'site2', 'id': 52},
{'name': 'site3', 'id': 66}}
, .