forEach vs For...of

Benchmark created on


Preparation HTML

<script>
var testArray = [];
for (var i = 0; i < 1000; i++) {
  testArray.push(i);
}

function testForOfLoop() {
  for (var item of testArray) {
    return item;
  }
}

// ใช้ forEach ในการทำงานกับ Array
function testForEach() {
  testArray.forEach(function(item) {
    return item;
  });
}
<script>

Test runner

Ready to run.

Testing in
TestOps/sec
for...of
testForOfLoop();
ready
foreach
testForEach();
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.