I was working on some code that return the unique objects in an array.
I found some code that does the trick, but it's not exactly what I need.
Right now let's say I have this array:
restuls= [
{
name: "name 1",
description: "",
group: "group 1"
},
{
name: "name 1",
description: "",
group: "group 1"
},
{
name: "name 1",
description: "",
group: "group 2"
},
]
With the code below, I find all unique objects in this array, meaning, if ANY of the values in the object are different, it will be a unique. So, in this case It will return 2 objects (because on the 3rd object --> group: "group 2").
var array = results,
unique = Array.from(
new Set(array.map(o => JSON.stringify(o))),
s => JSON.parse(s)
);
What I actually want is that it removes all duplicate objects, but only looking at "name" So, in this case, all 3 objects have the same name, so only one should be displayed.
Any ideas?