Monday, March 19, 2018

equals - javascript library for comparing objects











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.



Answer



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


No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...