I have two arrays containing some objects and I need to know how to combine them and exclude any duplicates. (For example, the object that contains apple: 222 from the second array should be excluded, if it already exists in the first array.)
Check below:
var arr1 = [
{apple: 111, tomato: 55},
{apple: 222, tomato: 55}
]
var arr2 = [
{apple: 222, tomato: 55},
{apple: 333, tomato: 55}
]
I want the result to be like this:
var res = [
{apple: 111, tomato: 55},
{apple: 222, tomato: 55},
{apple: 333, tomato: 55}
]
How can I do that in javascript?