i am trying to compare two objects. The ages are different but still says they are same.. here is my code
var personA =
{
name: "Josh Kloss",
age: 33
}
var personmB =
{
name: 'Josh Kloss',
age: 43
}
function compareTwoPeople(a, b) {
var person1 = Object.keys(a);
var person2 = Object.keys(b);
if (person1.length !== person2.length) {
console.log("They are not same");
}
else {
for (var i = 0; i < person1.length; i++) {
if (person1[i] === person2[i]) {
console.log("They are same");
}
}
}
}
compareTwoPeople(personA, personmB);
How can i compare these two object... Thanks.