Underscore.js _.isEqual() Function
Last Updated :
14 Jan, 2024
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 not.
Syntax:
_.isEqual(object, other);
Parameters:
- object: The object can be an array.
- other: The other array holds.
Return value:
It returns true if the arrays passed are the same otherwise it returns false.
Passing 2 simple arrays to the _.isEqual() function:
Underscore.js _.isEqual() function takes the element from the list of one array and searches it in the other array. If that property is found with the same value in the other array then it just goes on to check the other property otherwise it just returns false. In this, it checks for both the character values and the number values in the property.
Example: It shows the use of the Underscore.js _.isEqual() Function by passing two simple arrays.
HTML
< html >
< head >
< script src =
</ script >
</ head >
< body >
< script type = "text/javascript" >
let arr1 = {name: 'akash', numbers: [3, 7, 14]};
let arr2 = {name: 'akash', numbers: [3, 7, 14]};
console.log(_.isEqual(arr1, arr2));
</ script >
</ body >
</ html >
|
Output:

Passing an array with more properties to the _.isEqual() function:
An array can have as many properties as it has to act as a parameter to this function. Like here both the arrays contain 3 properties each of type character and date. The _.isEqual() function will work in the same way as for the above example. Since both the arrays have the same properties and the same values so, the output will be ‘true’.
Example: It shows the use of the Underscore.js _.isEqual() Function by passing an array with more properties.
html
< html >
< head >
< script src =
</ script >
</ head >
< body >
< script type = "text/javascript" >
let arr1 = {name: 'akash', gender: ['male'], birthDate: [03/22/99]};
let arr2 = {name: 'akash', gender: ['male'], birthDate: [03/22/99]};
console.log(_.isEqual(arr1, arr2));
</ script >
</ body >
</ html >
|
Output:

Passing 2 empty arrays to the _.isEqual() function:
Underscore.js _.isEqual() function will try to check all the array properties along with their values. Since both the array does not have any property so, there is nothing to match. And hence, both arrays are equal. Therefore, the answer will be true.
Example: It shows the use of the Underscore.js _.isEqual() Function by passing two wmpty arrays.
html
< html >
< head >
< script src =
</ script >
</ head >
< body >
< script type = "text/javascript" >
let arr1 = {};
let arr2 = {};
console.log(_.isEqual(arr1, arr2));
</ script >
</ body >
</ html >
|
Output:

Passing arrays with different properties to the _.isEqual() function:
If we pass arrays containing different properties then this function will work the same way. It will take the property of the first parameter array ( here, ‘name’) and try to find it in the next array. But since the other array does not have this property so the output will be ‘false’.
Example: It shows the use of the Underscore.js _.isEqual() Function by passing arrays with different properties.
html
< html >
< head >
< script src =
</ script >
</ head >
< body >
< script type = "text/javascript" >
let arr1 = {phoneNo: 4345656543};
let arr2 = {name: 'ashok'};
console.log(_.isEqual(arr1, arr2));
</ script >
</ body >
</ html >
|
Output:

NOTE: These commands will not work in Google Console or in Firefox as these additional files need to be added which they didn’t have added. So, add the given links to your HTML file and then run them. The links are as follows:
<script type="text/javascript" src =
"https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js">
</script>
An example is shown below:

Similar Reads
Underscore.js _.isNull() Function
Underscore.js _.isNull() function It is used to find whether the value of the object is null. If an object has a null value then the output will be true otherwise false. We can even perform addition, subtraction, etc operations in this function. Syntax:Â _.isNull(object);Parameters:It takes only one
3 min read
Underscore.js _.isSet() Function
Underscore.js is a library in javascript that makes operations on arrays, string, objects much easier and handy. _.isSet() function is used to check whether the given object is javascript set or not. When linking the underscore.js CDN The "_" is attached to the browser as global variable. Syntax: _.
2 min read
Underscore.js _.isMap() Function
Underscore.js is a library in javascript that makes operations on arrays, string, objects much easier and handy. _.isMap() function is used to check whether the given object is javascript Map or not. Note: It is very necessary to link the underscore CDN before going and using underscore functions in
2 min read
Underscore.js _.isNaN() Function
_.isNaN() function: It is used to find whether the value of the object passed is NaN or not.If the object's value is NaN then the output will be true otherwise, it will be false.We can even perform addition, subtraction etc operations in this function. Syntax: _.isNaN(object) Parameters:It takes onl
3 min read
Underscore.js _.isDate() function
Underscore.js is a javascript library that is capable enough to handle arrays, strings, objects, map, set very easily and efficiently. The _.isDate() function in underscore.js is used to tell if the given object is a date object or not. Syntax: _.isDate(object); Parameters: It takes only one paramet
1 min read
Underscore.js _.isMatch() Function
It _.isMatch() function: is used to find out if the property given in argument is present in the passed array or not. Also, the property's value should be the same in order to match. It is used in cases where we want to find whether the array satisfies a specific condition or not. Syntax:_.isMatch(o
3 min read
Underscore.js _.isBoolean() Function
The Underscore.js is a JavaScript library that provides a lot of useful functions like the map, filter, invoke, etc even without using any built-in objects. The _isBoolean function is used to find whether the element passed is true/ false or something else. Boolean is a subset of algebra that is use
3 min read
Underscore.js _.isError() Function
Underscore.js is a library in javascript that makes operations on arrays, string, objects much easier and handy. _.isError() function is used to check whether the given object is javascript Error Object or not. Note: It is very necessary to link the underscore CDN before going and using underscore f
2 min read
Underscore.js _.isElement() Function
The _.isElement() function: is used to check whether the element is a document object model or not. A document object model is the way javascript sees the data of the containing pages. The Cascading style sheet (CSS) and javascript (JS) interact with Document object model (DOM). Syntax:_.isElement(o
3 min read
Underscore.js _.isArray() Function
The Underscore.js is a JavaScript library that provides a lot of useful functions like the map, filter, invoke, etc even without using any built-in objects. The _.isArray() function is used to find whether the passed argument is an array or not. An array is a set of variables, constants, and special
3 min read