As shown on MDN, Map
's forEach
callback is called with value first, and then key. E.g.:
map.forEach(function(value, key, map) { ... })
Seems like key, value
is a lot more common than value, key
. Even the Map
constructor expects an array of [key, value]
pairs.
It's probably just for laziness sake. Most forEach loops will only care about the value
itself. By supplying it as the first parameter, you can construct a function that only accepts one parameter:
map.forEach(function (value) { /* do something with value */; })
Instead of
map.forEach(function (unused, value) { /* do something with value */; })
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With