My Current Tools
- Angular 5
- AngularFire5
- Firebase & Firestore
My Goal
I aim to iterate through an array containing objects. If a specific value in one object matches the same value in another object, I want to add their corresponding values together.
For Example:
Starting Data:
mapData = [{"countryCode":"US", "clicks": 5}, {"countryCode":"CAN", "clicks": 9}, {"countryCode":"US", "clicks": 6}]
or
mapData = [["US", 5], ["CAN", 9], ["US", 6]]
Desired Output:
mapDataResults = {
"US": {
"usage": 11,
"fillKey": "tens"
},
"CAN": {
"usage": 9,
"fillKey": "ones"
},
}
Where I Need Assistance
I am unsure how to efficiently search and match object values within the array. Additionally, I need help reformatting the data from an array to JSON format. Lastly, I would like to add a new key "fillKey" based on the number of clicks (or usage) for each country, which I believe I can do once the other steps are resolved.