This question already has an answer here:
What is the best way to compare objects in JavaScript?
Example:
var user1 = {name : "nerd", org: "dev"};
var user2 = {name : "nerd", org: "dev"};
var eq = user1 == user2;
alert(eq); // gives false
I know that two objects are equal if they refer to the exact same object, but is there a way to check if they have the same attributes' values?
The following way works for me, but is it the only possibility?
var eq = Object.toJSON(user1) == Object.toJSON(user2);
alert(eq); // gives true
Simple way to compare ONE-LEVEL only objects.
Here is my version, pretty much stuff from this thread is integrated (same counts for the test cases):
Here is my TestCase:
If you work without the JSON library, maybe this will help you out:
if you want to check for methods explicitly you can use the method.toSource() or method.toString() methods.