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
}
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 ?
The first one (the standard for-loop) performs much better according to this test.
Newer language features often don't perform as well at first because they haven't been given as much attention for optimization.
The more people use them, the more likely they'll get attention, so overall, use whichever one provides better, clearer code unless you have an extreme situation where performance is crucial.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With