by mschuetz · 8y ago · 0 comments
At least https://jsperf.com/for-vs-foreach/293 shows that there is no significant difference in for of vs forEach in my version of chrome. There is an insignificant difference acoording to which forEach is actually slower. (One forEach case in that benchmark is only faster because it does something different.)
Edit: looking at the comparison at the bottom, it seems like forEach is actually significant slower than for of since chrome 61.
There are many reasons it is faster, but it also has the nice property of working sensibly on any iterable object rather than forEach that only iterates by index, and has an annoying ‘if (index in object)’ in the loop.
Thanks for that!