Skip to content

Instantly share code, notes, and snippets.

@C-Rodg
Created March 21, 2017 03:47
Show Gist options
  • Save C-Rodg/d39d5f2a0ba501e891dfd3e7e04a43f1 to your computer and use it in GitHub Desktop.
Save C-Rodg/d39d5f2a0ba501e891dfd3e7e04a43f1 to your computer and use it in GitHub Desktop.
A Javascript function to test for object equality.
function isObjectEqual(a, b) {
let aProps = Object.getOwnPropertyNames(a),
bProps = Object.getOwnPropertyNames(b);
if (aProps.length !== bProps.length) {
return false;
}
for (let i = 0; i < aProps.length; i++) {
let propName = aProps[i];
if(a[propName] !== b[propName]) {
return false;
}
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment