I have this array:
"order": [
{ "item_name": " Corn Pie",
"item_status": "ready",
"extras": ["French Fries","Bacon"]
},
{ "item_name": " Corn Pie",
"item_status": "ready",
"extras": ["French Fries","Bacon"]
},
{ "item_name": " Corn Pie",
"item_status": "ready",
"extras": ["French Fries","Bacon"]
},
{ "item_name": " Corn Pie",
"item_status": "ready",
"extras": ["French Fries","Bacon"]
},
{ "item_name": " Corn Pie",
"item_status": "ready",
"extras": []
},
{ "item_name": " Corn Pie",
"item_status": "ready",
"extras": ["French Fries"]
},
{ "item_name": " Corn Pie",
"item_status": "waiting",
"extras": ["French Fries","Bacon"]
}]
and so I need to find which objects are duplicated.. to be duplicated all the 3 properties must be the same.. I can achieve that by doing this:
order = order.filter((item, index, self) =>
index === self.findIndex((t) => (
(t.item_name === item.item_name) && (t.item_status === item.item_status) && (t.extras.length === item.extras.length)
))
)
this code is working like a charm.. I can understand why and how it works but I need to know which elements were filtered and how many times it did.
any ideas? thanks in advance.. I took that filter from this post post filter
from the author Eydrian, I wish I could post a comment to ask directly there but I dont have the reputation to make comments.. so here I am ..
to be more clear, what i need is to know which elements where duplicated and how many times it got filtered, for example this element
{ "item_name": " Corn Pie",
"item_status": "ready",
"extras": ["French Fries","Bacon"]
}
is going to get filtered 4 times I need to know that information