I have two arrays of objects:
var objArray1 = [{'name':'abc', 'phone':'0333'},
{'name':'xyz', 'phone':'0334'},
{'name':'fgfh', 'phone':'0999'},
{'name':'abc', 'phone':'0666'},
{'name':'abc', 'phone':'0444'}
]
var objArray2 = [{'name':'abc', 'mobile':'0333'},
{'name':'xyz', 'mobile':'0334'},
{'name':'fgfh', 'mobile':'0999'}
]
I want to search index phone of objArray1 from objArray2.
If matches i want that object of objArray1 to be pushed in existing array, if no matches then push that object in joiners array.
Here is what i am trying to do.
objArray1.forEach(function(item){
if (objArray2.indexOf(item.phone) < 0) {
joiners.push(item)
}else{
existing.push(item)
}
})
Above code is not working and putting all objects of objArray1 into joiners.
Current Result:
joiners = [{'name':'abc', 'phone':'0333'},
{'name':'xyz', 'phone':'0334'},
{'name':'fgfh', 'phone':'0999'},
{'name':'abc', 'phone':'0666'},
{'name':'abc', 'phone':'0444'}
]
Wanted Result:
joiners = [{'name':'abc', 'phone':'0666'},
{'name':'abc', 'phone':'0444'}
]
And after that i want to check vise versa and make an array of leavers if any object of objArray2 do not exist in objArray1.