In Lodash, we can deeply compare two objects using the _.isEqual()
method. This method will compare both values to determine if they are equivalent.
_.isEqual(value1, value);
This method accepts the following parameters:
value1
: This is the value to be compared.value2
: This is the other value to be compared.This method returns true
if both values are equivalent, and vice-versa.
Let’s look at an example of a deep comparison between two objects using the _.isEqual()
method in the code snippet below.
In the HTML tab, we see the following:
lodash
script.In the JavaScript tab, we see the following:
obj1
, obj2
, and obj3
respectively, and initialize them.obj1
and obj2
and print the result on the console.obj1
and obj3
and print the result on the console.