How can I store duplicate keys in a key value pair in Angular ?
For eg -
I want to store -
101 , 999
101 , 989
101 , 987
102 , 888
102 , 887
I tried with this -
commentMap = new Map<number, number>();
this.commentMap.set(101,999);
this.commentMap.set(101,989);
this.commentMap.set(101,987);
this.commentMap.set(102,888);
this.commentMap.set(102,887);
I tried doing this but this allows only unique key values , any way I can store in any data structure like this in angular ?
The Map object holds key-value pairs so you need a different types for the key/value. You can change the value type to an array of numbers:
commentMap = new Map<number, number[]>();
commentMap.set(102,[888, 887]);
And now you can fetch it like so:
commentMap.get(102); // [888, 887]