Answers for "javascript compare if two objects are equal"

11

Javascript compare two objects

var person1={first_name:"bob"};
var person2 = {first_name:"bob"}; 

//compare the two object
if(JSON.stringify(person1) === JSON.stringify(person2)){
    //objects are the same
}
Posted by: Guest on July-25-2019
1

check if two objects are equal javascript

function checkObjEqual(obj1,obj2){
for(let key in obj1){
  if(!(key in obj2 )) return false;
  if(obj1[key]!==obj2[key])return false;
}
return true;
}

console.log(checkObjEqual({maroon:'#800000',purple :'#800080'},{purple :'#800080',maroon:'#800000'})) //true
Posted by: Guest on June-23-2021

Code answers related to "javascript compare if two objects are equal"

Code answers related to "Javascript"

Browse Popular Code Answers by Language