Skip to content

Instantly share code, notes, and snippets.

@yuval-a
Last active February 13, 2023 16:56
Show Gist options
  • Save yuval-a/a4fb717d0e827c208c7dd660dc514bae to your computer and use it in GitHub Desktop.
Save yuval-a/a4fb717d0e827c208c7dd660dc514bae to your computer and use it in GitHub Desktop.
Simple objects equality checker function
// 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