Run details:
Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Mobile Safari/537.36
Chrome Mobile 120
Android
Mobile
one year ago
Test name Executions per second
foreach 93.1 Ops/sec
for 54.7 Ops/sec
map 86.5 Ops/sec
Script Preparation code:
AخA
 
   var arr = [];
    for (var i = 0; i < 100000; i++) {
      arr[i] = i;
    }
  
    function someFn(i) {
      return i * 3 * 8;
    }
Tests:
  • foreach

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

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

     
    arr.map(item => someFn(item))