I am Looking For a way to remove Duplicates in a JSON Object with java script
var data = [
{
'id' : '1',
'name' : 'xyz',
'color' : 'red',
},
{
'id' : '2',
'name' : 'abc',
'color' : 'blue',
},
{
'id' : '3',
'name' : 'def',
'color' : 'black',
},
{
'id' : '1',
'name' : 'xyz',
'color' : 'black',
},
{
'id' : '4',
'name' : 'hij',
'color' : 'blue',
},
{
'id' : '2',
'name' : 'abc',
'color' : 'blue',
},
{
'id' : '5',
'name' : 'klm',
'color' : 'yellow',
},
{
'id' : '3',
'name' : 'def',
'color' : 'red',
},
];
For example i want to remove duplicate id based on the color selected giving priority to red, Black, Blue, Yellow in that order. so if there are two duplicates and person selected red and yellow, red should be kept.
Let me know if you need more clarification.
Thank You Het