Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36
Chrome 97
Windows
Desktop
3 years ago
Test name Executions per second
for 62381.8 Ops/sec
foreach 126123.7 Ops/sec
some 129991.1 Ops/sec
for..of 123182.7 Ops/sec
Script Preparation code:
x
 
var array = [];
for (let i = 0; i < 100; ++i) {
  array.push(i)
}
Tests:
  • for

     
    for (var i = 0; i < array.length; i++) {
      array[i];
    }
  • foreach

     
    array.forEach(function(i) {
      array[i];
    });
  • some

     
    array.some(function(i) {
      array[i];
    });
  • for..of

     
    for (var i of array) {
      array[i];
    }