I'm currently using ng2-charts and I'm looking to create a horizontal bar chart. The values are obtained within a keys.forEach loop, resulting in the console.log output for my data as follows:
{ReasonA: 5}
{ReasonA: 5, ReasonB: 5}
{ReasonA: 1, ReasonB: 3, ReasonC: 2}
{ReasonA: 1, ReasonB: 4, ReasonE: 2}
My goal is to merge these objects into one, consolidating multiple values under the same key. The expected outcome in this scenario would be:
{ReasonA: 12, ReasonB: 12, ReasonC: 2, ReasonE: 2}
Having achieved this merged object, I can then separate the keys and values to populate the chart. Could you provide guidance on how to combine the 4 objects into the desired result?
Thank you in advance.