How to group or merge this array of objects in javascript? : <p>I have an array of objects like below for example.     </p>

<pre><code>{name: "Mc Donald", quantity: 4, maleCount: 1, femaleCount: 0}
{name: "KFC", quantity: 9, maleCount: 1, femaleCount: 0}
{name: "KFC", quantity: 9, maleCount: 1, femaleCount: 0}
{name: "Mc Donald", quantity: 4, maleCount: 0, femaleCount: 1}
{name: "KFC", quantity: 9, maleCount: 0, femaleCount: 1}
{name: "KFC", quantity: 9, maleCount: 1, femaleCount: 0}
{name: "KFC", quantity: 9, maleCount: 0, femaleCount: 1}
{name: "KFC", quantity: 9, maleCount: 0, femaleCount: 1}
</code></pre>

<p>I want to group them up and adding up all the values in it. For example, the final would be like this: </p>

<pre><code>{name: "Mc Donald", quantity: 8, maleCount: 1, femaleCount: 1}
{name: "KFC", quantity: 54, maleCount: 3, femaleCount: 3}
</code></pre>

<p>How can I achieve this in JavaScript?</p>

<p>I have tried to find some solution online but it is not the one I wanted. For example this <a href="https://stackoverflow.com/questions/31688459/group-array-items-using-object">solution</a></p>
