typescript flattens an array of maps

You can use Array.reduce and create a new Map with the result:

let map1 = new Map([['a', 1], ['b', 2]]);
let map2 = new Map([['c', 3], ['d', 4]]);
let maps = [map1, map2];

// reduce to a flattened array
let arr = maps.reduce((acc, val) => [...acc, ...val], []);

// create a new map using that array
let map3 = new Map(arr);

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top