I also like ES5 array functions and in my opinion they’re a few of the best additions to the language. My favorites are
map. The problem with these functions is they are synchronous, and I find myself trying to do something like this:
Which clearly isn’t going to work out since the callback function passed to
map needs to have a return value. A possible solution to this is turn each array item into a
Promise object and wait for all promises to resolve using
Promise.all. Something like:
This solution is alright, until you need to do it repeatedly then it will get verbose pretty fast. So I made a small helper library to do it.
This super small library provides async versions of
filter which return a
Promise with the result. Take this example:
It’s possible to return a new
Promise or a normal value from the callback.
promise-arrays is available to use with Node.JS, UMD and browser globals. Check it out on Github and please report any issues. All suggestions are also welcome :-)