Skip to content

Instantly share code, notes, and snippets.

@rijkvanzanten
Created October 11, 2016 14:44
Show Gist options
  • Save rijkvanzanten/e5a9dbc005d5c534d4a55804414dddfb to your computer and use it in GitHub Desktop.
Save rijkvanzanten/e5a9dbc005d5c534d4a55804414dddfb to your computer and use it in GitHub Desktop.
Function which checks if two objects are equal
function isEqual(obj1, obj2) {
const props1 = Object.getOwnPropertyNames(obj1);
const props2 = Object.getOwnPropertyNames(obj2);
if(props1.length != props2.length) {
return false;
}
for(let i = 0; i < props1.length; i++) {
const propName = props1[i];
if(obj1[propName] !== obj2[propName]) {
return false;
}
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment