Answers for "compare objects"

10

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
5

how to compare javascript objects

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;
}
Posted by: Guest on August-16-2020
0

compare objects

//No generic function to do that at all.
//use Lodash, famous for such must have functions, all efficiently built
//http://lodash.com/docs#isEqual --- npm install lodash

_.isEqual(object, other);
Posted by: Guest on September-01-2021

Code answers related to "compare objects"

Code answers related to "Javascript"

Browse Popular Code Answers by Language