Skip to content
Advertisement

How to merge the multiple object if the key value equal

I have an array of objects. In each object, I have the ‘date’ key. if the ‘date’ value is matched with another object, I need to add the ‘amount’ property and make it a new object.

JavaScript

My expected output should be:

JavaScript

Kindly help me to solve it.

Advertisement

Answer

You can use Array.reduce to calculate a sum per date value. Something like:

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement