Say we have a Map: let m = new Map();
, using m.values()
returns a map iterator.
But I can\'t use forEach()
or map()
o
There is a proposal, that is bringing multiple helper functions to Iterator
: https://github.com/tc39/proposal-iterator-helpers (rendered)
You can use it today by utilizing core-js
:
import { from as iterFrom } from "core-js-pure/features/iterator";
// or if it's working for you:
// import iterFrom from "core-js-pure/features/iterator/from";
let m = new Map();
m.set("13", 37);
m.set("42", 42);
const arr = iterFrom(m.values())
.map((val) => val * 2)
.toArray();
// prints "[74, 84]"
console.log(arr);