compare object to object javascript code example
Example 1: Javascript compare two objects
var person1={first_name:"bob"};
var person2 = {first_name:"bob"};
if(JSON.stringify(person1) === JSON.stringify(person2)){
}
Example 2: compare objects in javascript
function shallowEqual(object1, object2) {
const keys1 = Object.keys(object1);
const keys2 = Object.keys(object2);
if (keys1.length !== keys2.length) {
return false;
}
for (let key of keys1) {
if (object1[key] !== object2[key]) {
return false;
}
}
return true;
}