5

Possible Duplicate:
How do you determine equality for two JavaScript objects?
Object comparison in JavaScript

Are there any javascript libraries that can help with comparing two objects for equivalence? So if I have something like

var obj1 = {"name":"Jeff", "gender":"M", "arrayprop":[1,2,3] };
var obj2 = {"name":"Jeff", "gender":"M", "arrayprop":[1,2,3] };

And I would like obj1 and obj2 to return "equal" since they have the same properties/values.

Obviously obj1 === obj2 returns false, but I didn't know if there was a function already available I could use that would return true.

4
  • Voted down. Question has been asked repeatedly (see comments above) Commented Dec 7, 2012 at 19:57
  • This was specifically asking if there are any libraries that help with it Commented Dec 7, 2012 at 20:02
  • (Revised) True, but it really is a fine line. The answer you accepted was mentioned in 2/3 of the possible duplicates listed above and all 3 had answers based on library solutions. This was my first down vote; I seriously try to avoid them. In this case, looking at your stats I would've expected a search beforehand. After seeing the question I did a quick Google search to find a library-less version. The first two potential duplicates were the top 2 results returned from Google Commented Dec 7, 2012 at 20:55
  • I did search (and found those questions), but I overlooked the underscore.js mentions. You are correct though, I should have read the search results more carefully. Commented Dec 7, 2012 at 21:01

1 Answer 1

8

There is Underscore.js with the function isEqual() : http://underscorejs.org/#isEqual

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.