JavaScript: Compare the structure of two JSON objects while ignoring their values
This is an elegant solution. You could do it simple like this:
var equal = true;
for (i in object1)
if (!object2.hasOwnProperty(i))
equal = false;
If the two elements have the same properties, then, the var equal
must remain true
.
And as function:
function compareObjects(object1, object2){
var equal = true;
for (i in object1)
if (!object2.hasOwnProperty(i))
equal = false;
return equal;
}