Loop through associative array in reverse

前端 未结 4 1676
陌清茗
陌清茗 2020-12-14 08:37

I\'m using a javascript associative array (arr) and am using this method to loop through it.

for(var i in arr) {
    var value = arr[i];
    alert(i =\") \"+         


        
4条回答
  •  孤街浪徒
    2020-12-14 09:33

    For a normal array, I would have done this:

    var i = arr.length;
    while (i--) {
        var value = arr[i];
        alert(i =") "+ value);
    }
    

    This is faster than a "for" loop.

    http://blogs.oracle.com/greimer/entry/best_way_to_code_a

提交回复
热议问题