So I can call map()
on an array to iterate through it and return another array, like so:
[1,2,3].map( (value, index) => value * index )
What if I want to do the same over a Map object?
var myMap = new Map();
myMap.set(0, 1);
myMap.set(1, 2);
myMap.set(2, 3);
This isn't valid:
myMap.map( (value, index) => value * index )
There's a forEach but that's not the same.
Is there a quick shorthand way to generate an array from a Map
, like map()
does on an array?
– hopefully that sentence makes sense.