const map1: Map<string, string> = new Map([
["a", "aaa"],
["b", "bbb"]
]);
const map2: Map<string, string> = new Map([
["c", "ccc"],
["b", "XYZ"], // Overwrites 'b'
["d", "ddd"]
]);
const combined: Map<string, string> = new Map(map1);
for (const [key, value] of map2) {
if (combined.has(key)) {
combined.set(key, combined.get(key) + ", " + value); // Merge values
} else {
combined.set(key, value);
}
}
console.log(combined);
/*
run:
Map (4) {"a" => "aaa", "b" => "bbb, XYZ", "c" => "ccc", "d" => "ddd"}
*/