The Wayback Machine - https://web.archive.org/web/20241130063838/https://www.geeksforgeeks.org/lodash-_-isequal-method/
Open In App

Lodash _.isEqual() Method

Last Updated : 09 Oct, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Lodash _.isEqual() Method performs a deep comparison between two values to determine if they are equivalent. This method supports comparing arrays, array buffers, boolean, date objects, maps, numbers, objects, regex, sets, strings, symbols, and typed arrays. 

Syntax:

_.isEqual( value1, value2);

Parameters:

  • value1: First comparable value
  • value2: Second comparable value

Return Value:

  • This method returns a Boolean value(Returns true if the two values are equal, else false).

Note: Objects are compared directly, their inherited or enumerable properties are not compared. Functions and DOM nodes are compared strictly by the ‘===’ operator.

To further develop your skills with JavaScript libraries like Lodash, consider our JavaScript Course, which includes lessons on enhancing your JavaScript code by leveraging popular utility libraries.

Example 1: In this example, We are comparing two variables having objects as a value and printing results in the console.

JavaScript
// Defining Lodash variable 
const _ = require('lodash');

// First value
let val1 = { "a": "gfg" };

// Second value
let val2 = { "b": "gfg" };

// Checking for Equal Value 
console.log("The Values are Equal : "
    + _.isEqual(val1, val2));

Output:

The Values are Equal : false

Example 2: In this example, We are comparing two variables having Array as a value and printing results in the console.

JavaScript
// Defining Lodash variable 
const _ = require('lodash');

let val1 = [1, 2, 3, 4]

let val2 = [1, 2, 3, 4]

// Checking for Equal Value 
console.log("The Values are Equal : "
    + _.isEqual(val1, val2));

Output:

The Values are Equal : true

Example 3: In this example, We are comparing two variables having String as a value and printing results in the console.

JavaScript
// Defining Lodash variable 
const _ = require('lodash'); 

let val1 = "gfg"

let val2 = "gfg"

// Checking for Equal Value 
console.log("The Values are Equal : "
        +_.isEqual(val1,val2));

Output:

The Values are Equal : true

Example 4: In this example, We are comparing two variables having Numbers as a value and printing results in the console.

JavaScript
// Defining Lodash variable 
const _ = require('lodash');

let val1 = 1

let val2 = 1

// Checking for Equal Value 
console.log("The Values are Equal : "
    + _.isEqual(val1, val2));

Output:

The Values are Equal : true

Lodash _.isEqual() Method – FAQs

What is _.isEqual() used for?

_.isEqual() performs a deep comparison between two values to determine if they are equivalent.

How do you use _.isEqual()?

Use _.isEqual(value, other), where value and other are the items to compare.

Can _.isEqual() compare nested objects?

Yes, it compares nested objects deeply, checking each level for equality.

Does _.isEqual() handle functions within objects?

No, functions are compared by reference, not by their content or behavior.

Can _.isEqual() handle circular references?

No, it does not handle circular references and will result in an error.



Previous Article
Next Article

Similar Reads

Underscore.js _.isEqual() Function
Underscore.js _.isEqual() function: is used to find whether the 2 given arrays are the same or not. Two arrays are the same if they have the same number of elements, both the property and the values need to be the same. It may be beneficial in situations where the elements of the array are not known and we want to check whether they are the same or
4 min read
Lodash _.method() Method
Lodash _.method() method creates a function that invokes the method at the path of a given object. Any additional arguments are provided to the invoked method. Syntax: _.method(path, args);Parameters: path: This is the path to invoke.args: These are the arguments to invoke the method with.Return Value: This method returns the new invoker function.
1 min read
Lodash _.stubFalse() Method
Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, strings, objects, numbers, etc. The _.stubFalse() method is used to always return a false value. The basic difference between using a normal false value and using the _.stubFalse() method is that lambda functions create a new different functi
1 min read
Lodash _.toArray() Method
Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, strings, objects, numbers, etc. The _.toArray() method is used to convert the given value to an array. Syntax: _.toArray( value ) Parameters: This method accepts a single parameter as mentioned above and described below: value: This parameter
1 min read
Lodash _.splitAt() Method
The Lodash _.splitAt() method takes an array and a numeric index and returns a new array containing two embedded arrays made by splitting the original array at the provided numeric index. Syntax: _.splitAt(array, numeric_index) Parameters: This method takes two parameters as mentioned above and described below: array: The array to be split.numeric_
3 min read
Lodash _.stubString()Method
The Lodash _.stubString() method is used to create an empty string. Syntax: _.stubString() Parameters: This method does not accept any parameter. Return Value: This method returns an empty string. Example 1: C/C++ Code // Requiring the lodash library const _ = require("lodash"); // Use of _.stubString() method // to create an empty String
1 min read
Lodash _.curry2() Method
The Lodash _.curry2() method returns a curried version of the given function but will curry exactly two arguments, no more or less. Syntax: _.curry2( fun ) Parameters: This method takes a single parameter as listed above and discussed below. fun: This is the given function. Return Value: It returns a curried version of the function. Note: To execut
2 min read
Lodash _.at() Method
Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, collection, strings, lang, function, objects, numbers etc. The _.at() method creates an array of values corresponding to paths of object. Syntax: _.at(object, [paths]) Parameters: This method accepts two parameters as mentioned above and desc
2 min read
Lodash _.conformTo() Method
Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, collection, strings, objects, numbers etc. The _.conformsTo() method checks if object conforms to source by invoking the predicate properties of source with the corresponding property values of object and this method is equivalent to _.confor
2 min read
Lodash _.cycle() Method
Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, strings, objects, numbers, etc. The _.cycle() method is then used to build a new array containing the given number of iterations of the given array, that are string end-to-end. Thus, the new array created contains the given array number of gi
2 min read
Lodash _.cat() Method
Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, strings, objects, numbers, etc. The _.cat() method is used to concatenate zero or more arguments into one array. It can be used to concatenate multiple types of arguments, Syntax: _.cat( arg1, arg2, ..., argn ) Parameters: args: This method a
2 min read
Lodash _.chunkAll() Method
Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, strings, objects, numbers, etc. The _.chunkAll() Method is used to break the given array in to small chunks of the given size. It is similar to the _.chunk() method except that this method will never drop short chunks from the end. Syntax: _.
2 min read
Lodash _.keepindexed() Method
Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, strings, objects, numbers, etc. The _.keepIndexed() method takes an array and a function as parameters and returns a new array filled with the non-null return results of the given function acted upon the elements of the given array. Syntax: _
2 min read
Lodash _.keep() Method
The Lodash _.keep() method takes an array and a function and hence returns an array generated which keeps only true values based on the conditions of the function. Syntax: _.keep( array, function ) Parameters: This method takes two parameters as mentioned above and described below: array: The given array from which keep array is created.function: T
2 min read
Lodash _.weave() Method
The Lodash _.weave() method takes two arrays and returns an array with both arrays woven together. Note: The array returned from _.weave() method will be woven till the shortest array, rest array values will be the same. Syntax: _.weave(array1, array2) Parameters: This method takes two parameters as mentioned above and described below: array1: The
2 min read
Lodash _.second() Method
The Lodash _.second() method takes an array and an index and hence returns an array generated by taking elements from the original array starting with the second element and ending at the given index. Syntax: _.second(array, index); Parameters: This method takes two parameters as mentioned above and described below: array: The given array from the
3 min read
Lodash _.best() Method
The Lodash _.best() method takes an array and a function and generates the best suitable value from that array using the conditions of the function. Syntax: _.best(array, function) Parameters: This method accepts two parameters as mentioned above and described below: array: The given array from which the best value is calculated.function: The funct
2 min read
Lodash _.third() Method
The Lodash _.third() method takes an array and an index and hence returns an array generated by taking elements from the original array starting with the third element and ending at the given index. Syntax: _.third(array, index); Parameters: This method takes two parameters as mentioned above and described below: array: The given array from the ele
3 min read
Lodash _.constant() Method
Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, strings, objects, numbers, etc. The _.constant method is used to create a function that returns value. Syntax: _.constant(value) Parameters: This method accepts one parameter as mentioned above and described below: value: The value to return
1 min read
Lodash _.invoke() Method
Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, collection, strings, lang, function, objects, numbers etc. The _.invoke() method is invoked the method at path of object. Syntax: _.invoke(object, path, args) Parameters: This method accepts three parameters as mentioned above and described b
2 min read
Lodash _.cons() Method
The Lodash _.cons() Method is used to construct a new array by taking some element and putting it at the front of another array or element. Syntax: _.cons(element, Array_or_element); Parameters: element: It is the element that gets put in the front to construct a new Array.Array_or_element: It is the second parameter used to construct an array. Ret
2 min read
Lodash _.iterateUntil() Method
The Lodash _.iterateUntil() Method takes two functions, one is used as a result generator, other function used as a stop-check and a seed value say n and returns an array of each generated result. The operation of _.iterateUntil() method is such that the result generator is passed with the seed value at the start and each subsequent result which wi
2 min read
Lodash _.entriesIn() Method
The _.entriesIn() method is used to create an array of own and inherited enumerable string keyed-value pairs for the specified object. If object is a map or set, its entries are returned. Syntax: _.entriesIn(object) Parameters: This method accepts a parameter as mentioned above and described below: object: This parameter holds the object to query.
1 min read
Lodash _.extend() Method
The _.extend() method is like the _.assign() method except that it iterates over its own and inherited source properties. Syntax: _.extend(object, sources) Parameters: This method accepts two parameters as mentioned above and described below: object: This parameter holds the destination object.sources: This parameter holds the source objects. Retur
1 min read
Lodash _.always() Method
The Lodash _.always() method takes a value and returns a function that will always return that value. Syntax: _.always( value ); Parameters: This method takes a single parameter as listed above and discussed below. value: This method takes a value to be returned. Return Value: This method returns a function. Note: To execute the below examples, you
1 min read
Lodash _.bound() Method
The Lodash _.bound() method returns function which is a property of an object by name, bound to the object made. Syntax: _.bound( obj, function); Parameters: This method accepts two parameters as listed above and discussed below. obj: the object in which the function is defined.function: a function defined containing the returning logic. Return Val
1 min read
Lodash _.comparator() Method
The Lodash _.comparator() method takes a binary predicate-like function and returns a comparator function which can be used as a callback for _.sort() method etc. Syntax: _.comparator( function ); Parameters: This method accepts a single parameter as listed above and discussed below. function: It is a predicate like defined function. Return Value:
2 min read
Lodash _.complement() Method
The Lodash _.complement() method returns a function that reverses the sense of a given predicate-function. Syntax: _.complement( function ); Parameters: This method accepts a single parameter as listed above and discussed below. function: This parameter predicate function defined containing the returning logic. Return Value: This method returns a f
1 min read
Lodash _.juxt() Method
The Lodash _.juxt() method returns a function whose return value is an array of the results after calling each of the functions with the given arguments. Syntax: _.juxt( function1, function2, .., function ); Parameters: This method accepts n functions containing the logic to return values. Return Value: This method returns a function. Note: To exec
1 min read
Lodash _.flip2() Method
The Lodash _.flip2() method returns a function that works identically to the given function but accepts the first two arguments in reverse order. The order of all rest arguments remains the same. Syntax: _.flip2( function ); Parameters: This method accepts a single parameter as mentioned above and defined below: function: This method takes a functi
2 min read
three90RightbarBannerImg