且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在JavaScript中循环数组的最快方法是什么?

更新时间:2022-04-20 21:19:27

用大多数现代浏览器执行此测试后......

After performing this test with most modern browsers...

http://jsben.ch/y3SpC

目前 ,最快的循环形式(在我看来,语法最明显)。

Currently, the fastest form of loop (and in my opinion the most syntactically obvious).

标准具有长度缓存的循环

a standard for loop with length caching

for (var i = 0, len = myArray.length; i < len; i++) {

}

我想这肯定是我鼓掌JavaScript引擎的情况开发人员。运行时间应针对清晰度进行优化,不要聪明

I would say this is definitely a case where I applaud JavaScript engine developers. A run time should be optimized for clarity, not cleverness.