You want to iterate through each element in a and check if there are any matches on b, if not, add it to the output.
function getElementsInANotInB(a,b){
var results = []
for(var i=0;i<a.length;i++){
var in_b = false
// check if any element in b matches a[i]
for(var u=0;u<b.length;u++){
if(compareObjects(a[i],b[u])){
in_b = true
break
}
}
if(!in_b) // no element in b matched a[i], add to results
results.push(a[i])
}
return results
}
function compareObjects(obj1,obj2,reversed){
// search for differences recursively
for(var key in obj1){
if(typeof obj2[key]=="undefined") return false
if(typeof obj1[key] == "object"){
if(!compareObjects(obj1[key],obj2[key])) return false
}
else if(obj1[key]!=obj2[key]) return false
}
return reversed ? true : compareObjects(obj2,obj1,true)
}
Calling getElementsInANotInB(a,b)
should give you the desired array containing all elements in a, which are not in b.