JavaScript for…in vs for

前端 未结 22 1472
悲哀的现实
悲哀的现实 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条回答
  •  无人共我
    2020-11-22 07:36

    If you really want to speed up your code, what about that?

    for( var i=0,j=null; j=array[i++]; foo(j) );
    

    it's kinda of having the while logic within the for statement and it's less redundant. Also firefox has Array.forEach and Array.filter

提交回复
热议问题