Skip to content

Instantly share code, notes, and snippets.

@htmelvis
Created May 4, 2022 13:11
Show Gist options
  • Save htmelvis/fe71ff012356f6e4d223e56a721ef36e to your computer and use it in GitHub Desktop.
Save htmelvis/fe71ff012356f6e4d223e56a721ef36e to your computer and use it in GitHub Desktop.
isEqual Object Equality
const isEqual = (a, b) => JSON.stringify(a) === JSON.stringify(b);
// examples
isEqual({ a: 1, b: 2 }, { a: 1, b: 2 }); // true
isEqual({ a: 1, b: 2 }, { a: 1, b: 3 }); // false
// works with arrays too
isEqual([1, 2, 3], [1, 2, 3]); // true
isEqual([1, 2, 3], [1, 2, 4]); // false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment