I have an array of objects which i receive from a db:
[{
key: 'PRODUCT',
item_key: 'ITEM_01',
sequence: 1
},
{
key: 'STORE',
item_key: 'STORE_01',
sequence: 2
}
]
I want to create a Map from it but the condition is, i want the item_key to be the map key, and only the corresponding array element which matches the item_key will be the value of that map key. So the map looks like
{
'ITEM_01' => [{
key: 'PRODUCT',
item_key: 'ITEM_01',
sequence: 1
}],
'STORE_01' => [{
key: 'STORE',
item_key: 'STORE_01',
sequence: 2
}]
}
I've kept the value of map keys as an array because there can be more values matching the map key in future. How can i do this?
P.S. by Map i don't mean the array function map, but the JS/TS Map
there can be more values matching the map key in futureIt might be a good idea to update your example showing this. As this is pretty much fundamental to the question, as your will likely wantreducenotmap..reduce,. Your example data does not show a duplicate, so I was pointing out it would be a good idea to show it, as it's a pretty fundamental aspect of your output.