I recommend to always use for … of
in ES6.
- It works on any iterable
- It supports all kinds of control flow in the loop body, like
continue
,break
,return
,yield
andawait
.
Also I personally find it more readable, but that comes down to preference. Some people think forEach
is a more functional style, but that’s wrong – it has no result value and is all about doing side effects, so an imperative-looking loop fits that purpose better.
Performance is not a concern, in modern engines all loop styles are equivalent.