Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Efficient looping through AS3 dictionary

for (var k in dictionary)  {   var key:KeyType = KeyType(k);   var value:ValType = ValType(dictionary[k]); // <-- lookup   // do stuff } 

This is what I use to loop through the entries in a dictionary. As you can see in every iteration I perform a lookup in the dictionary. Is there a more efficient way of iterating the dictionary (while keeping access to the key)?

like image 977
Bart van Heukelom Avatar asked Mar 05 '10 12:03

Bart van Heukelom


1 Answers

Iterate through keys & values:

for (var k:Object in dictionary) {     var value:ValType = dictionary[k];     var key:KeyType = k; } 

Iterate through values more concisely:

for each (var value:ValType in dictionary) {  } 
like image 95
Patrick Avatar answered Nov 11 '22 16:11

Patrick