Is it possible to "filter" a Map by value in Typescript? Is it possible to "filter" a Map by value in Typescript? angular angular

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 ] ] 


This one uses Object.entries to convert the map to an array, and Object.fromEntries to convert back to map.

let qs = {a:'A 1',b:null,c:'C 3'};let qsfiltered = Object.fromEntries(    Object.entries(qs).filter(([k,v]) => v !== null));console.log(JSON.stringify(qsfiltered));