DEV Community

Discussion on: Looping through objects in JavaScript

Collapse
 
kepta profile image
Kushan Joshi • Edited

I totally agree with you regarding for loop and how .map, .reduce, .filter are a heavenly match for functional programming. But there are cases where I feel for of loop is a natural fit:

  • Iterator: Javascript now has native support for iterators (I talk about them in my article), so dealing with Map, Set, Array etc, the for of loop becomes a natural choice over converting these iterators to arrays and then applying the functional methods.

  • Async: Another area I find for of loop a rather easier read is when I have to iterate through an async collection. I talk about some examples of async for loop here.