

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the importance of _isEqual() method in JavaScript?
_isEqual()
_isEqual() is from the underscore and lodash library of javascript. It is used to compare javascript objects. The importance of this method is that it doesn't care about the order of properties while comparing the objects. It only checks whether the properties in the two objects are equal or not. Whereas JSON.stringify(), which is used in comparing the objects, checks even the order of properties of the objects, making _isEqual() the better option.
syntax
_.isEqual(object1, object2);
It accepts two objects as parameters and scrutinizes whether they are equal or not.
Example
<html> <head> <script src = "https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js"> </script> </head> <body> <script> var obj1 = {name: "Sikha", designation: "Content developer"}; var obj2 = {name: "Sikha", designation: "Content developer"}; document.write(_.isEqual(obj1, obj2)); </script> </body> </html>
Output
true
In the following example, Both JSON.stringify() and _isEqual() methods are used. Since the order of properties is not a problem for the _isEqual() method it gives out true as output whereas JSON.stringify() gives out false as output.
Example
<html> <head> <script src = "https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js"> </script> </head> <body> <script> var obj1 = {name: "Sikha", designation: "Content developer"}; var obj2 = {designation: "Content developer", name: "Sikha"}; document.write(_.isEqual(obj1, obj2)); document.write("</br>"); document.write(JSON.stringify(obj1) === JSON.stringify(obj2)); </script> </body> </html>
Output
true false
- Related Questions & Answers
- What is the importance of Math.trunc() method in JavaScript?
- What is the importance of _.union() method in JavaScript?
- What is the importance of _without() method in JavaScript?
- What is the importance of str.padStart() method in JavaScript?
- What is importance of startsWith() method in JavaScript?
- What is the importance of Symbol.isConcatSpreadable in JavaScript?
- What is the importance of _.initial() function in JavaScript?
- What is the importance of Navigator Object in JavaScript?
- What is the importance of hygiene?
- What is the importance of Computer?
- Write the importance of shift() method in javascript array?
- What is the importance of '/g' flag in JavaScript?
- What is the importance of '/i' flag in JavaScript?
- What is the importance of Hindu rituals?
- What is the importance of operating systems?