I'm not looking for an answer for simple array, but I am facing a problem when I have nested level array of objects.
So far I have seen similar answers for simple arrays but not for a complex nested one.
Below is my duplicate array, it has sub-level of items and objects, and I want to match the file object name and find the duplicate based on that.
I tried to apply below function but, it does not work for me. Please tell me how to modify the below function to my array?
var myArr = [
{file: {name: "sakthi1.jpg"}, checked: true},
{file: {name: "sakthi2.jpg"}, checked: true},
{file: {name: "sakthi2.jpg"}, checked: true},
{file: {name: "sakthi2.jpg"}, checked: true}
];
function removeDuplicates(myArr, prop) {
return myArr.filter((obj, pos, arr) => {
return arr.map(mapObj => mapObj[prop]).indexOf(obj[prop]) === pos;
});
}