How do I sum of similar properties in array of objects

I asked a similar question earlier today, but the output of this question is different. I asked wrongly the first time :(

I have a large array, which I have simplified for the question purpose

  {"item1": 3, "item40": 2},
  {"item1": 4, "item40": 8}

I would like to end up with this, which is the sum of each similar property in the array of objects. I tried a lot. Doing a forEach whith a forIn inside. But I am stuck. Please help :)

[7, 10]

Read more here:

Content Attribution

This content was originally published by Johansrk at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: