I have 2 arrays of objects which contain same properties, but depending on situation they can have 1-50 properties. I need to get difference between those 2
Array 1:
[
{
"prop1": 1,
"prop2": 2
},
{
"prop1": 4,
"prop2": 4
},
{
"prop1": 3,
"prop2": 7
},
{
"prop1": 1,
"prop2": 3
}
]
Array 2:
[
{
"prop1": 1,
"prop2": 2
},
{
"prop1": 4,
"prop2": 4
}
]
I tried with underscore's difference function but it doesn't work well in this scenario. I was thinking of getting object keys, sorting it and hasnhing the objects.That I can compare but I need to get it back into original format. And since these arrays can have up to 5000 object it seems costly.
Is there an effecient solution?
Edit: I have seen the question Difference between two array of objects in JavaScript but that example has static number of properties on which he filters the arrays. That is not the case; I do not know names, nor quantity of properties.