I have searched on here for a quality method to compare associative arrays in javascript. The only decent solution I have found is the PHP.JS project which has some comparat
I really don't know if there is a nicer way to do it than the brute force approach:
function differences(a, b){
var dif = {};
for(key in a){ //In a and not in b
if(!b[key]){
dif[key] = a[key];
}
}
for(key in a){ //in a and b but different values
if(a[key] && b[key] && a[key]!=b[key]){
//I don't know what you want in this case...
}
}
for(key in b){ //in b and not in a
if(!a[key]){
dif[key] = b[key];
}
}
return dif;
}
Also, they are objects, not arrays, and some properties will not be enumerable through for..in (like Array.length, for example), so take it into account for your application.