Loading...
const names = new Map([[1, 'Ann'], [2, 'Bob']]);
const upper = Array.from(names.values())
.map((n) => n.toUpperCase());const names = new Map([[1, 'Ann'], [2, 'Bob']]);
const upper = names.values()
.map((n) => n.toUpperCase())
.toArray();map() runs on the iterator directly, so no intermediate array is built before mapping.
map() on an iterator to return an array.Map, Set or generator are mapped on the iterator, without Array.from() first.toArray(), for...of or another helper, otherwise nothing runs.map() return an array?No. It returns a new lazy iterator; call toArray() or loop with for...of to get the values.
map() callback?A counter that starts at 0. Unlike array map(), there is no third argument with the source.