So I have this object, and have to merge it with same selectionID, but also keep the topicName (and not overwrite it)
[
   {
      "selectionId":1,
      "topicName":"topic created or not validate"
   },
   {
      "selectionId":1,
      "topicName":"hghhhg test test"
   },
   {
      "selectionId":2,
      "topicName":"topic test"
   },
   {
      "selectionId":3,
      "topicName":"new topic for test topic name and description name(test check)"
   },
   {
      "selectionId":4,
      "topicName":"topic check check"
   },
   {
      "selectionId":4,
      "topicName":"topic check popup"
   },
   {
      "selectionId":5,
      "topicName":"test"
   }
]
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.
[
   {
      "selectionId":1,
      ["topicName":"topic created or not validate", "topicName":"hghhhg test test"] 
   }
   {
      "selectionId":2,
      "topicName":"topic test"
   }{
      "selectionId":3,
      "topicName":"new topic for test topic name and description name(test check)"
   }{
      "selectionId":4,
      ["topicName":"topic check check","topicName":"topic check popup"]
   }{
      "selectionId":5,
      "topicName":"test"
   }
]
I have tried this:
  var result = list.filter(function(v) {
        return this[v.selectionId]?
          !Object.assign(this[v.selectionId], v):
          (this[v.selectionId] = v);
      }, {});
Answer: (It does not take the topicName)
[
{selectionId: 1, topicName: "hghhhg test test"}
{selectionId: 2, topicName: "topic test"}
{selectionId: 3, topicName: "new topic for test topic name and description name(test check)"}
{selectionId: 4, topicName: "topic check popup"}
{selectionId: 5, topicName: "test"}
]
EDIT: Thank you guys! All the answers have worked! And giving results as expected.
 
     
     
    