How would you do this? Instinctively, I want to do:
var myMap = new Map([[\"thing1\", 1], [\"thing2\", 2], [\"thing3\", 3]]);
// wishful, ignorant thinking
Using Array.from
I wrote a Typescript function that maps the values:
function mapKeys(m: Map, fn: (this: void, v: V) => U): Map {
function transformPair([k, v]: [T, V]): [T, U] {
return [k, fn(v)]
}
return new Map(Array.from(m.entries(), transformPair));
}
const m = new Map([[1, 2], [3, 4]]);
console.log(mapKeys(m, i => i + 1));
// Map { 1 => 3, 3 => 5 }