If anybody is interested in the performance side of the multiple mechanisms available for Array iterations , i'veI've prepared the following JSPerf tests:
https://jsperf.com/fastest-array-iterator
Results :
The traditional for()
iterator, is by far the fastest method, speciallyespecially when used with the array length cached.
let arr = [1,2,3,4,5];
for(let i=0, size=arr.length; i<size; i++){
// doDo something
}
The Array.prototype.forEach()
and the Array.prototype.map()
methods are the slowest approximations, probably as a consequence of the function call overhead.