In my JavaScript code, I'm receiving data from a WebService that looks like this:
{
"fire": {
"totalOccurence": 2,
"statsByCustomer": [
{
"idCustomer": 1,
"occurence": 1
},
{
"idCustomer": 2,
"occurence": 1
}
]
},
"flood": {
"totalOccurence": 1,
"statsByCustomer": [
{
"idCustomer": 1,
"occurence": 1
}
]
}
}
I need to create the following object based on this data:
{
"1": {
"fire": 1,
"flood": 1
},
"2": {
"fire": 1,
"flood": 0
}
}
Currently, I am using multiple forEach loops to format the data, but I believe there might be a better and more efficient way to achieve this. PS: The customer Id should be used as the key in the result map.
If you have any suggestions on how to optimize this process, I would greatly appreciate your input!
Thank you for your assistance!