forEach for for in for of性能問題


var arr = new Array(1000); console.time('forEach'); arr.forEach(data => { }); console.timeEnd('forEach'); console.time('for'); for (var i = 0; i < arr.length; ++i) { }; console.timeEnd('for'); console.time('for in'); for (var i in arr) {}; console.timeEnd('for in'); console.time('for of'); for (var i of arr) {}; console.timeEnd('for of');

  打印結果爲javascript

結論性能爲forEach > for in > for > for of java

相關文章
相關標籤/搜索