I have an array of objects like this:
var bigarr =
[
[ { name: 'ABC',id: 391},{ name: 'XYZ',id: 545}],
[ { name: 'EFG',id: 390},{ name: 'XYZ',id: 545}],
[ { name: 'XYZ',id: 545},{ name: 'ABC',id: 391}],
[ { name: 'ABC',id: 391},{ name: 'XYZ',id: 545}]
];
How can I remove any of the duplicated pair of objects that have id545 and 391 to reduce the array to this:
var newbigarr =
[
[ { name: 'ABC',id: 391},{ name: 'XYZ',id: 545}],
[ { name: 'EFG',id: 390},{ name: 'XYZ',id: 545}]
];
I have thought of filtering out the duplicated pairs by making a new list of array:
[{391: 391,545: 545},{390: 390,545: 545}]
and then iterating over it and bigarr to build the newbigarr, but my code isn't even able to create that list to begin with.
var test_id = [];
for(var i = 0;i < bigarr.length;i++)
{
var value_obj = {};
for(var j in bigarr[i])
{
var value = bigarr[i][j]["id"];
value_obj[value] = value;
}
test_id.push(value_obj);
}
console.log(test_id);
I'm using lodash,so any solution involving lodash is welcomed.