Created
May 4, 2022 13:11
-
-
Save htmelvis/fe71ff012356f6e4d223e56a721ef36e to your computer and use it in GitHub Desktop.
isEqual Object Equality
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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