title: How to merge multiple array objects with the same key?
body: <p>So I have this object, and have to merge it with same selectionID, but also keep the topicName (and not overwrite it)</p>
  <pre><code>[
     {
        &quot;selectionId&quot;:1,
        &quot;topicName&quot;:&quot;topic created or not validate&quot;
     },
     {
        &quot;selectionId&quot;:1,
        &quot;topicName&quot;:&quot;hghhhg test test&quot;
     },
     {
        &quot;selectionId&quot;:2,
        &quot;topicName&quot;:&quot;topic test&quot;
     },
     {
        &quot;selectionId&quot;:3,
        &quot;topicName&quot;:&quot;new topic for test topic name and description name(test check)&quot;
     },
     {
        &quot;selectionId&quot;:4,
        &quot;topicName&quot;:&quot;topic check check&quot;
     },
     {
        &quot;selectionId&quot;:4,
        &quot;topicName&quot;:&quot;topic check popup&quot;
     },
     {
        &quot;selectionId&quot;:5,
        &quot;topicName&quot;:&quot;test&quot;
     }
  ]
  </code></pre>
  <p>Now I want to merge the selectioId, but also append the topicName to a new array in the same object so that I can loop it to display accordingly.</p>
  <pre><code>[
     {
        &quot;selectionId&quot;:1,
        [&quot;topicName&quot;:&quot;topic created or not validate&quot;, &quot;topicName&quot;:&quot;hghhhg test test&quot;] 
     }
     {
        &quot;selectionId&quot;:2,
        &quot;topicName&quot;:&quot;topic test&quot;
     }{
        &quot;selectionId&quot;:3,
        &quot;topicName&quot;:&quot;new topic for test topic name and description name(test check)&quot;
     }{
        &quot;selectionId&quot;:4,
        [&quot;topicName&quot;:&quot;topic check check&quot;,&quot;topicName&quot;:&quot;topic check popup&quot;]
     }{
        &quot;selectionId&quot;:5,
        &quot;topicName&quot;:&quot;test&quot;
     }
  ]
  </code></pre>
  <p>I have tried this:</p>
  <pre><code>  var result = list.filter(function(v) {
          return this[v.selectionId]?
            !Object.assign(this[v.selectionId], v):
            (this[v.selectionId] = v);
        }, {});
  </code></pre>
  <p>Answer: (It does not take the topicName)</p>
  <pre><code>[
  {selectionId: 1, topicName: &quot;hghhhg test test&quot;}
  {selectionId: 2, topicName: &quot;topic test&quot;}
  {selectionId: 3, topicName: &quot;new topic for test topic name and description name(test check)&quot;}
  {selectionId: 4, topicName: &quot;topic check popup&quot;}
  {selectionId: 5, topicName: &quot;test&quot;}
  ]
  </code></pre>
  <p>EDIT:
  Thank you guys!
  All the answers have worked!
  And giving results as expected.</p>