title: Remove duplicates from an array of objects and Add new Value (e.g. Quantity) in JavaScript
body: <p>I have an object that contains an array of objects. I want to remove the duplicated object and i want to append it with new value such as quantity.</p>
  <pre><code>const data = [{
        id: &quot;B01&quot;,
        image: &quot;https://i.ibb.co/zmdvMfD/zinger-stacke-burger.png&quot;,
        title: &quot;Zinger Stack&quot;,
        price: 3.99,
      },
      {
        id: &quot;B01&quot;,
        image: &quot;https://i.ibb.co/zmdvMfD/zinger-stacke-burger.png&quot;,
        title: &quot;Zinger Stack&quot;,
        price: 3.99,
      },
      {
        id: &quot;F01&quot;,
        image: &quot;https://i.ibb.co/zmdvMfD/zinger-stacke-burger.png&quot;,
        title: &quot;Zinger Stack&quot;,
        price: 3.99,
      },
      {
        id: &quot;F01&quot;,
        image: &quot;https://i.ibb.co/zmdvMfD/zinger-stacke-burger.png&quot;,
        title: &quot;Zinger Stack&quot;,
        price: 3.99,
      },
      ]
  
  </code></pre>
  <p>This is what i want to achieve</p>
  <pre><code>const data = [
      {
        id: &quot;B01&quot;,
        image: &quot;https://i.ibb.co/zmdvMfD/zinger-stacke-burger.png&quot;,
        title: &quot;Zinger Stack&quot;,
        price: 3.99,
        quantity: 2
      },
      {
        id: &quot;F01&quot;,
        image: &quot;https://i.ibb.co/zmdvMfD/zinger-stacke-burger.png&quot;,
        title: &quot;Zinger Stack&quot;,
        price: 3.99,
        quantity: 2
      }
      ]
  </code></pre>
  <p>This one is my solution. is there any shorthand/ faster way to achieve the same result ?</p>
  <pre><code>  let ids = data.map((o) =&gt; o.id);
    let uniqueList = data.filter(({ id }, index) =&gt; !ids.includes(id, index + 1));
  
    console.log(&quot;uniqueList&quot;, uniqueList);
  
  
   const result = uniqueList.map((item) =&gt; {
      return {
        ...item,
        quantity: (data.reduce((totalType, item) =&gt; {
          if (!totalType[item.id]) {
            totalType[item.id] = 0;
          }
      
          totalType[item.id]++;
      
          return totalType;
        }, {}))[item.id]
      };
    });
  
    console.log(&quot;result &gt;&quot;, result);
  
  </code></pre>