I have a structure of
JavaScript
x
2
1
Array(4) [Map(1),Map(1),Map(1),Map(1)]
2
All keys are different there. I am trying find the common way to merge it in one Map.
I know the way for two Maps:
JavaScript
1
2
1
let merged = new Map([first, second])
2
But for this solution I need more common way.
Advertisement
Answer
You are looking for flatMap:
JavaScript
1
8
1
const arr = [
2
new Map([[1, 2]]),
3
new Map([[3, 4]]),
4
];
5
6
const merged = arr.flatMap(e => [e])
7
8
console.log(merged)