I need to compare two objects, and find out what properties are missing. The objects are fairly big, with several levels.
I will give short example of the type of object
function compare(base, compared, deepSearch) {
var missing = [];
var compareProp = function (baseValue, comparedValue, path, deepSearch) {
//console.log('comparing', path.join('.'));
if (comparedValue === undefined) {
console.log('missing key', path.join('.'));
if (!deepSearch) {
return;
}
}
if (typeof baseValue === 'object') {
Object.keys(baseValue).forEach(function (key) {
compareProp(baseValue [key], comparedValue && comparedValue [key], path.concat(key), deepSearch);
});
}
};
Object.keys(base).forEach(function (key) {
compareProp(base [key], compared [key], [key], deepSearch);
});
}
UC = {};
UC.start = {}
UC.start.enableHardEccDecline = '';
UC.start.template = {};
UC.start.template.ecc = '';
UC.start.template.decline = {};
UC.start.template.decline.title = '';
UC.start.template.decline.body = '';
UC.general = {};
compare (UC, {}, true);