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);
Thank you. Now, I am using Object.getOwnPropertyNames() instead of Object.keys() to solve the problem.
Object.getOwnPropertyNames()
Object.keys()
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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.
Thank you. Now, I am using
Object.getOwnPropertyNames()instead ofObject.keys()to solve the problem.