DEV Community

Discussion on: Deeply Compare 2 Objects with Recursive Function in JavaScript

Collapse
 
zlm11 profile image
zlm11 • Edited

Good article,however there is one problem, as Object.keys not include unenumerable properties, so if one obj has unenumerable property but the other not, the result expected false but true.

let obj3 = {
  name: "Rahim",
  additionalData: {
    instructor: true,
    favoriteHobbies: ["Playing Cricket", "Tennis", "Coding"],
    citiesLivedIn: ["Rajshahi", "Rangpur", "Joypurhat"]
  }
};
Object.defineProperty(obj3, 'noneEnumble', {
  value: 123,
  enumerable: false
});

let obj4 = {
  name: "Rahim",
  additionalData: {
    instructor: true,
    favoriteHobbies: ["Playing Cricket", "Tennis", "Coding"],
    citiesLivedIn: ["Rajshahi", "Rangpur", "Joypurhat"]
  }
};
console.log(deepComparison(obj3, obj4));
console.log(obj3.noneEnumble);
Enter fullscreen mode Exit fullscreen mode
Collapse
 
rasaf_ibrahim profile image
Rasaf Ibrahim • Edited

Thank you. Now, I am using Object.getOwnPropertyNames() instead of Object.keys() to solve the problem.