Javascript for loop efficiency

后端 未结 5 710
我寻月下人不归
我寻月下人不归 2021-01-04 10:01

Is

for (var i=0, cols=columns.length; i

more efficient than

for (var i=0; i

        
5条回答
  •  醉话见心
    2021-01-04 10:27

    Yes, it is. Accessing the length property wastes un-needed time (unless the array's length can change during iteration.).

    Here is how I loop through arrays: http://gist.github.com/339735

提交回复
热议问题