DEV Community

Discussion on: 4 Javascript Array Methods to Use Daily

Collapse
 
wulymammoth profile image
David • Edited

My favorite has become Array.prototype.reduce. I haven't written JS seriously in over two years, though. Reduce is so general purpose that it can be used to mimic all of the above. I resort to this often if I need a new data type, like performing some operation on the elements in the array and dumping them into a map or object or simply to avoid mutating the original input array

One thing that may also be worth noting is that all of the above should only be used if the intention is to enumerate the entire array with no early termination conditions. In those scenarios, one must use the standard for-loop, while loop, or reduce (skipping past values on conditions).

Nice write-up, though!

Collapse
 
kenovienadu profile image
Ovienadu Ken

You're absolutely right. Array.prototype.reduce has been a major helper in dire situations.