Thank you for your feedback. Quoting MDN, the documentation does say it returns a single value.
single value
The reduce() method executes a reducer function (that you provide) on each element of the array, resulting in a single output value.
I'm pretty new to the method, may I know more about your last reference to thisArg please?
thisArg
Single value doesn't mean it can't be a collection type I think is the OP's point. For example you can use reduce to easily make a lookup map out of an array:
[ { id: 123, name: "Ben" }, { id: 456, name: "Sarah" }, { id: 789, name: "Jane" } ].reduce((acc, e) => { return { [e.id]: e.name, ...acc } }, {}) /* output- { 123: Ben, 456: Sarah, 789: Jane } */
Yes, thank you for a nice example.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
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.
Thank you for your feedback. Quoting MDN, the documentation does say it returns a
single value
.I'm pretty new to the method, may I know more about your last reference to
thisArg
please?Single value doesn't mean it can't be a collection type I think is the OP's point. For example you can use reduce to easily make a lookup map out of an array:
Yes, thank you for a nice example.