Tech News
← Back to articles

JavaScript's For-Of Loops Are Fast

read original related products more articles

JavaScript's for-of loops are actually fast

Published on 01/01/2026

Updated on 04/01/2026

When it comes to iterating over arrays, for...of loops are believed to be significantly slower than traditional indexed loops. This has some grounding, since for-of loops are based on the iteration protocol, where the iterator has next() method returning an object like this: { value: /* element value */, done: /* a boolean, indicating the end of iteration */ } . Obviously, returning such object for every element will add an overhead.

However, I decided to test this since JS engines are constantly improving and sometimes can do amazing optimizations.

The benchmark

I decided to do the benchmarks with jsbenchmark.com on Chrome 143, Windows 11 and AMD Ryzen 5000U. All the benchmark tests are run sequentially.

The core idea of the benchmark

The idea is to create 5 types of arrays: integers, floats, strings, objects and mixed values.

The benchmarks will be done with 3 array sizes: 5000, 50000, and 500000.

... continue reading