store = [{
"item": "shirt",
"price": 20
},
{
"item": "shirt",
"price": 50
},
{
"item": "pants",
"price": 10
},
{
"item": "pants",
"price": 20
}
]
//im filtering the array to get objects without duplication here
console.log(store.filter((v, i, a) => a.findIndex(v2 => ['item'].every(k => v2[k] === v[k])) === i))
and i would like to get the max price as well in the same filter so how would i get this output after excuting it ?
expected output:
[{
"item": "shirt",
"price": 50
},
{
"item": "pants",
"price": 20
}]