The map function might take you to the next level. Is pretty easy to use and works with Async code.
It might be slower then a classical for loop, but if you are planning on using Observables and playing with async arrays it’s the only option.
Let’s suppose we’ve got the following array of objects:
You can loop through the code above using the standard for loop and returns the symbol this way:
Or you can use the build in map method this way:
What it does it accepts a closure to which each element of the array is passed. Have a look below:
In this case we don’t have to take care of a for loop, we don’t need to create new variables. We just pass our array through the map() function.
If you want to check the performance have a look here: https://jsperf.com/map-vs-for-loop-performance/6