function isObject(obj) {
return typeof obj == 'object' && typeof obj !== null;
}
function isEqual(obj1,obj2) {
if ( !isObject(obj1) || !isObject(obj2)) {
return obj1 === obj2;
}
if ( obj1 === obj2 ) {
return true;
}
const obj1_key = Object.keys(obj1);
const obj2_key = Object.keys(obj2);
if ( obj1_key.length !== obj2_key.length ) {
return false;
}
for(key in obj1) {
const res = isEqual(obj1[key],obj2[key]);
if ( !res ) {
return false;
}
}
return true;
}
let obj1 = {
name:'obj',
num:'0'
}
let obj2 = {
name:'obj',
num:'0'
}
const res = isEqual(obj1,obj2);
console.log(res); //true