Object comparison in JavaScript
- by spankmaster79
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 it another way??
Using this way works for me.....but is it the only possibility?
var eq = Object.toJSON(user1) == Object.toJSON(user2);
alert(eq); // gives true