I have two arrays with objects and I want to compare them so I can get the objects that are not in array one, and those not in array two.
For example, if I have following two arrays:
var arrayOne = [{ "name":"John", "age":30},{ "name":"John", "age":35},{ "name":"John", "age":35}];
var arrayTwo = [{ "name":"John", "age":35},{ "name":"John", "age":40}];
...I want to match in such a way so I can get two new arrays like ResultOne
and ResultTwo
:
var ResultOne = [{ "name":"John", "age":40}]; //JSON new in Array Two
var ResultTwo = [{ "name":"John", "age":35},{ "name":"John", "age":40}]; //JSON NOT IN array TWO but in Array One
I tried all Q&A suggested on Stack Overflow, but can't find a way to get the arrays when two objects are the same, like I have {"name":"John", "age":35}
occuring two times in arrayOne
.