My personal tip is learn .reduce as soon as possible. It intimidated me for a long time and I used .forEach a lot. Once you get reduce you'll suddenly realise how powerful and straight-forward it is and basically never use .forEach again
My main use case for using .forEach before discovering .reduce was because I wanted to transform one object into a new object with a different shape. I'd create an empty object and then .forEach the original object's Object.entities/keys to add properties to the empty object, whereas this is more concise by simply using a .reduce
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
My personal tip is learn .reduce as soon as possible. It intimidated me for a long time and I used .forEach a lot. Once you get reduce you'll suddenly realise how powerful and straight-forward it is and basically never use .forEach again
Isn't reduce mainly for working with current values and a total value? How would that take the place of something like
.forEach()
entirely?Granted, I do think I have a use case for it, but I don't yet see the need for replacing something like
.forEach()
or.map()
entirely.My main use case for using
.forEach
before discovering.reduce
was because I wanted to transform one object into a new object with a different shape. I'd create an empty object and then.forEach
the original object's Object.entities/keys to add properties to the empty object, whereas this is more concise by simply using a.reduce