Whats the smartest / cleanest way to iterate async over arrays (or objs)?

Checkout the async library, it’s made for control flow (async stuff) and it has a lot of methods for array stuff: each, filter, map. Check the documentation on github. Here’s what you probably need:

each(arr, iterator, callback)

Applies an iterator function to each item in an array, in parallel. The iterator is called with an item from the list and a callback for when it has finished. If the iterator passes an error to this callback, the main callback for the each function is immediately called with the error.

eachSeries(arr, iterator, callback)

The same as each only the iterator is applied to each item in the array in series. The next iterator is only called once the current one has completed processing. This means the iterator functions will complete in order.

Leave a Comment