-3

Say we have an existing Map:

const m1 = new Map([['color', 'red'], ['owner', 'Flavio'], ['age', 2]])

if we want to create a new map, is it enough to do:

const m2 = new Map(m1);

or maybe instead:

const m2 = new Map(Array.from(m1))
Alexander Mills
  • 90,741
  • 139
  • 482
  • 817

1 Answers1

0

MDN says you could do this.

const first = new Map([
  [1, "one"],
  [2, "two"],
  [3, "three"]
]);

const second = new Map([
  [1, "uno"],
  [2, "dos"],
  [3, "tres"]
]);

const merged = new Map([...first, ...second]);

console.log(merged.get(1))
Helmer Barcos
  • 1,898
  • 12
  • 18