DEV Community

Discussion on: Stop abusing .map()!

Collapse
 
lethanhtupk profile image
Tu Le Thanh • Edited

Could you please tell what is the properly way to have side effects with each element in an array? I currently using side effects with map and promise.all

Collapse
 
totally_chase profile image
Phantz

Could you give an example of the usage that you need clarification with? Generally, if you're iterating over an array purely to perform side effects and are not interested in building a new array after mapping a function on each element - you would use a regular for..of loop.

Collapse
 
tanth1993 profile image
tanth1993

developer.mozilla.org/en-US/docs/W...
in this site, you will see, map function calls the callback() as synchronous function.
Therefore, there is no side effect items will be resolved.
You can use for or for... of to solve side-effect arrays