代码实例验证
let arrs = new Array(10000000);
console.time('for');
let len = arrs.length //大循环应该提前定义长度变量
for (let i = 0; i<len; i++) {
};
console.timeEnd('for');
console.time('forEach');
arrs.forEach((arr) => {
});
console.timeEnd('forEach');
//十万数据结果
for: 2.48291015625 ms
forEach: 0.386962890625 ms
//五十万数据结果
for: 3.162109375 ms
forEach: 2.213134765625 ms
//百万结果
for: 3.258056640625 ms
forEach: 4.404052734375 ms