console.timeEnd('reduceRight求和时间');//evalconsole.time('eval求和时间');var_sum = eval(aArr.join('+')); console.log('eval求和: '+_sum); console.timeEnd('eval求和时间');//forconsole.time('for(var i = 0,len = aArr.length;i < len;i++)求和时间');var_sum = 0;for(vari =...
JS 数组求和方法与性能比较 eval 函数#function sum(arr) { return eval(arr.join('+')) } for/forEach 循环#function sum(arr) { let res = 0 for (let i = 0, len = arr.length; i < len; i++) { res += arr[i] } return res } function sum(arr) { let res = 0 arr.forEach(...
JS 数组求和方法与性能比较 eval 函数#function sum(arr) { return eval(arr.join('+')) } for/forEach 循环#function sum(arr) { let res = 0 for (let i = 0, len = arr.length; i < len; i++) { res += arr[i] } return res } function sum(arr) { let res = 0 arr.forEach(...