

In this case, for of has much less of a 'code smell' than Array.forEach.

However, it is my opinion that side effects in array iteration is a bad practice and you should be explicit when you are looping over some iterator to produce side effects (e.g. This discussion has gone on for a while, and I am convinced that all for of statements could be transformed into Array.forEach statements. Symbol is not polyfillable nor available in every browser we support.ĭoesn't core-js (used by bable I believe) polyfillSymbol's, as well as well known symbols like the iterator symbol?Įdit: Just so I don't waste your time, is there a link to previous discussion on what decisions led to for of being disabled? Because surely stuff like iterating in a generator or async function is something that's been considered. There's also the fact you can't yield from a forEach for an outer function the same way you can with a for of, or you use await in an async function (unless this rule accommodates for this). However if the readability of isn't an issue for you, then this may be a non issue. It's less the ordering of the elements and more the ordering ordering of the parameters on invocation, the function you pass to jQuery forEach each passes the index through the first argument and the actual element in the second. I'm not sure why its element ordering really applies. True, but if the original argument against for of is that it isn't readability, then this isn't a strong argument in favour of forEach.
