kvzbpa
Last Updated: December 06, 2019
·
1.054M
· afshinm

Don't use Array.forEach, use for() instead

Array.ForEach is about 95% slower than for() in for each for Arrays in JavaScript.

So, don't use:

arr.forEach(function (item) {
someFn(item);
})

Use:

for (var i = 0, len = arr.length; i < len; i++) {
someFn(arr[i]);
}

See this performance test online: http://jsperf.com/fast-array-foreach

3 Responses
Add your response

34730

How about for of loop ?

7 days ago ·
34735

very good

6 days ago ·
34745

Thank you for this site!

about 1 hour ago ·