JavaScript for…in vs for

前端 未结 22 1193
悲哀的现实
悲哀的现实 2020-11-22 07:15

Do you think there is a big difference in for...in and for loops? What kind of \"for\" do you prefer to use and why?

Let\'s say we have an array of associative array

22条回答
  •  -上瘾入骨i
    2020-11-22 07:33

    A shorter and best code according to jsperf is

    keys  = Object.keys(obj);
    for (var i = keys.length; i--;){
       value = obj[keys[i]];// or other action
    }
    

提交回复
热议问题