DEV Community

Brian Liotti
Brian Liotti

Posted on

Answer: know your Javascript loops

TL;DR

  • Your best bets are usually

    • a for-of loop (ES2015+ only; spec | MDN) - simple and async-friendly
    • forEach (ES5+ only; spec | MDN) (or its relatives some and such) - not async-friendly (but see details)
    • a simple old-fashioned for loop - async-friendly
    • (rarely) for-in

Top comments (0)