var a = [
[
{
id: "AAA"
},
{
id: "BBB"
}
],
[
{
id: "AAA"
},
{
id: "DDD"
}
]
];
var b = [
[
{
id: "BBB"
}
],
[
{
id: "CCC"
},
{
id: "BBB"
}
],
[
{
id: "AAA"
}
],
[
{
id: "AAA"
},
{
id: "DDD"
}
],
[
{
id: "DDD"
}
],
[
{
id: "CCC"
},
{
id: "DDD"
}
],
[
{
id: "AAA"
}
],
[
{
id: "AAA"
},
{
id: "BBB"
}
]
];
function remove_duplicates(a, b) {
for (var i = 0, len = a.length; i < len; i++) {
for (var j = 0, len = b.length; j < len; j++) {
if (a[i].name == b[j].name) {
b.splice(j, 1);
}
}
}
console.log(a);
console.log(b);
}
console.log(a);
console.log(b);
remove_duplicates(a,b);
I have tried the filter and reduce but they are coming with desired result I found a similar one but the one I have got little different structure
seeking for possible solution from JavaScript or underscore
expected result: [[{"id":"BBB"}],[{"id":"CCC"},{"id":"BBB"}],[{"id":"AAA"}],[{"id":"DDD"}],[{"id":"CCC"},{"id":"DDD"}]]