Last active
February 13, 2023 16:56
-
-
Save yuval-a/a4fb717d0e827c208c7dd660dc514bae to your computer and use it in GitHub Desktop.
Simple objects equality checker function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Check if objects are equal (have the same keys with the same values), all values must be primitives (no functions, objects or arrays) | |
function areObjectsEqual(obj1, obj2) { | |
let obj1KeysCount = 0; | |
for (const key in obj1) { | |
if (obj1[key] !== obj2[key]) return false; | |
obj1KeysCount++; | |
} | |
return Object.keys(obj2).length === obj1KeysCount; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment