Why doesn't Map have a map method?

To map a Map object, you must first transfer it to an array of arrays. It seems to me the opposite.

Can someone explain to me that this is justified by the design? I understand that in other languages, such as Scala, there are map methods for Maps, so I'm trying to understand why they are not available in Javascript.

This syntax seems unnecessarily complex and verbose:

let mappedMap = new Map( [...originalMap] .map(([k, v]) => [k * 2, '_' + v]) ); 

Could it be something like this?

 let mappedMap = originalMap.map((k, v) => [k * 2, '_' + v]); 
+5
source share
1 answer

A map on ES6 is currently presented as an iteration using the key / value system. And the map function of the array returns a new array. I am not sure that it will be possible to return the new version in this way. I will use forEach for Maps and build new ones. If anything, if you can create a function with the same functionality, and I also definitely recommend exploring immutable.js

0
source

All Articles