I have an Array which holds another Array of objects. I would like to remove the duplicates in this array of array.
var arr1 = [{
child: [{name: "google", check: false}, {name: "yahoo", check: false}]
},
{
child: [{name: "excite", check: false}, {name: "facebook", check: false}]
},
{
child: [{name: "something1", check: false}, {name: "something2", check: false}]
}
]
var arr2 = [{
child: [{name: "google", check: true}, {name: "yahoo", check: false}]
},
{
child: [{name: "excite", check: false}, {name: "facebook", check: false}]
}
]
var arr3 = [{
child: [{name: "google", check: true}, {name: "yahoo", check: false}]
},
{
child: [{name: "excite", check: false}, {name: "facebook", check: false}]
},
{
child: [{name: "something1", check: false}, {name: "something2", check: false}]
}
]
I would like to remove {name: "google", check: false} from the second child array as there is already one with same name and check: true in arr1.
Below is something what i have tried.
function mergeAndRemoveDuplicates(arr1, arr2) {
return arr1.map(function(child) {
return child.some(function(children) {
return arr2.map(function(child2) {
return child2.some(function(children2) {
return children.name === children2.name &&
children.check === true;
});
})
})
})
}
console.log(mergeAndRemoveDuplicates(arr1, arr2));
arr1with the new upcoming data fromarr2. Is that what you really want?