Consider the following two JSON objects:
var obj1 = {a: "apple", b: "banana", c: "carrot"}
var obj2 = {a: "apple", e: “egg” b: "banana", c: "carrot", d: "dog"}
I'm looking for a way to compare these objects using a Boolean check without altering any of their data. In this scenario, the comparison should yield true because the values of matching keys in both objects are identical.
Now, let's suppose the first object (obj1
) remains the same, but the second one (obj2
) is as follows:
var obj1 = {a: "apple", b: "banana", c: "carrot"}
var obj2 = {a: "ant", e: “egg” b: "banana", c: "carrot", d: "dog"}
In this case, the Boolean check should return false because the value associated with key a does not match, even though some other fields do and some are exclusive to one object.
Any suggestions on how to approach this? I'd prefer utilizing Lodash due to its comprehensive feature set. Initially, I tried using _.isEqual(obj1, obj2)
, but it didn't meet my specific requirements.