Is it possible to "filter" a Map by value in Typescript?
It is
Array.from(map.values()).filter((item: Event) => item.event_id === eventId);
Or for TypeScript downlevelIteration
option,
[...map.values()].filter((item: Event) => item.event_id === eventId);
Here's a short syntax that keeps keys and values together:
const dict = new Map([["Z", 1324], ["A", 1], ["B", 2], ["C", 3], ["D", -12345]])const filtered = [...dict.entries()].filter( it => it[1] < 10 ) // > [ [ 'A', 1 ], [ 'B', 2 ], [ 'C', 3 ], [ 'D', -12345 ] ]
First you need to flatten the map, Then extract the contents to an Events
object
let dataSet = { "entry1" : { id: "85d55e6b-f4bf-47b0" }, "entry2" : { visitor_id: "6665b-7555bf-978b0" } } let flattenedMap = {}; Object.entries(dataSet).forEach( ([key,value]) => Object.assign(flattenedMap, value) ); console.log("The flattened Map")console.log(flattenedMap)let events = [];Object.entries(flattenedMap).forEach( ([key, value]) => events.push({"event_id" : value}));console.log("The events");console.log(events);