通过AS3词典高效循环高效、词典

2023-09-08 12:22:52 作者:爷的浪荡以失传

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)?

推荐答案

遍历键&放大器; 值

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

遍历值更简洁:

for each (var value:ValType in dictionary) {

}