Skip to content

Instantly share code, notes, and snippets.

@jordanhudgens
Created September 28, 2018 18:56
Show Gist options
  • Save jordanhudgens/18913a642cd7c511830e7a73b880fa7d to your computer and use it in GitHub Desktop.
Save jordanhudgens/18913a642cd7c511830e7a73b880fa7d to your computer and use it in GitHub Desktop.
const isEqual = (obj1, obj2) => {
const obj1Keys = Object.keys(obj1);
const obj2Keys = Object.keys(obj2);
if (obj1Keys.length !== obj2Keys.length) {
return false;
}
for (let objKey of obj1Keys) {
if (obj1[objKey] !== obj2[objKey]) {
return false;
}
}
return true;
};
const obj1 = {
name: "Kristine",
age: 13
};
const obj2 = {
name: "Kristine",
age: 13
};
obj1 == obj2; // false
isEqual(obj1, obj2); // true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment