JSFiddle - React, Tailwind, and code Playground
by ifightcrime
JavaScript
var iterations_to_perform = 9999999;
var my_arr = [];
for (var i=0; i < iterations_to_perform; i++) {
my_arr.push(i);
}
var sum = 0;
var start = new Date().getTime();
my_arr.forEach(function(index) {
sum += index;
});
console.log(new Date().getTime() - start);
sum = 0
function computeSum(index) {
sum += index;
}
start = new Date().getTime();
my_arr.forEach(computeSum);
console.log(new Date().getTime() - start);