Hello all, can anyone help me out with figuring out how I can check for objects inside objects and comparing their values?
Here’s my code.
function check(obj1, obj2) {
props1 = Object.getOwnPropertyNames(obj1);
props2 = Object.getOwnPropertyNames(obj2);
if (props1.length !== props2.length) {
return false;
}
for (let i=0; i < props1.length; i++) {
let prop = props1[i];
if (typeof obj1[prop] === 'object'){
check(obj1[prop], obj2[prop]);
}
if (obj1[prop] !== obj2[prop])
return false;
}
return true;
}
console.log(check({a: 1, b: {d: 1, e: 2}}, {a: 1, b: {d: 1, e: 2}}));