Imagine I have two sets of data:
const obj1 = {
CRITICAL: 0,
ERROR: 1,
INFO: 0,
WARNING: 0,
};
const obj2 = {
CRITICAL: 0,
ERROR: 0,
INFO: 0,
WARNING: 1,
};
I'm looking to merge them into a single object with the summed values for each property:
{
CRITICAL: 0,
ERROR: 1,
INFO: 0,
WARNING: 1,
};
The method I've used so far is:
Object.keys(obj1).reduce((prev, curr) => {
prev[curr] = obj1[curr] + obj2[curr];
return prev;
}, {});
However, I believe there may be more efficient ways to achieve this. Any suggestions on alternative approaches would be greatly appreciated.