Search code examples
javascriptfor-loopecmascript-6for-of-loop

Javascript simple for loop versus for...of performances


I have seen that since ECMA 6 we can use for...of instead of the traditionnal for loop:

for( let i = 0 ; i < arr.length ; i++ ) {
    var elm = arr[i];
    // do stuff
}

VS

for( let elm of arr ) {
    // do stuff
}

Has you see the second one is lot more readable, simple and maintainable!

I just wonder how performant the second syntax is as I need to use it a lot in a render loop (60 times per seconds) for a game.

Have you got a clue ?


Solution

  • The first one (the standard for-loop) performs much better according to this test.