This is an example of the object:
[{index: 0,name: "name 1",key: "key 1",value: "value 1"},{index: 0,name: "name 1",key: "key 2",value: "value 2"}]
I want to make it so the duplicated value are maintained, while the different value are added to the corresponding keys like so:
[{index: 0,name: "name 1",key: {"key 1", "key 2"}value: {"value 1", "value 2"}}]
I've tried doing something like this:
const object : [{index: 0, name: "name 1", key: "key 1", value: "value 1"}, {index: 0, name: "name 1", key: "key 2", value: "value 2"}]let new = [] for (let i = 0 ; i < object.length ; i++) { if (new.length === 0) { new.push({ index: object[i].index, name: object[i].name, key: object[i].key, value: object[i].value }) } else if (new.length > 0) { for (let a = 0 ; a < new.length ; a++) { if (new[a].index === object[i].index && new[a].name === object[i].name && new[a].key !== object[i].key) { new[a].key = object[i].key new[a].value = object[i].value } } } }
But it ended up overwriting the previous values