Skip to content
Related Articles

Related Articles

Lodash _.isEqual() Method
  • Last Updated : 31 Jul, 2020

The 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: This method accepts two parameters as mentioned above and described below:

  • value1: value1 to be checked.
  • value2: value2 to be checked.

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

Example 1: 



Javascript

filter_none

edit
close

play_arrow

link
brightness_4
code

// Defining Lodash variable 
const _ = require('lodash'); 
  
var val1 = { "a": "gfg" };
  
var val2 = { "a": "gfg" };
  
// Checking for Equal Value 
console.log("The Values are Equal : "
        +_.isEqual(val1,val2));

chevron_right


Output:

The Values are Equal : true

Example 2: For arrays: 

Javascript

filter_none

edit
close

play_arrow

link
brightness_4
code

// Defining Lodash variable 
const _ = require('lodash'); 
  
var val1 = [1, 2, 3, 4]
  
var val2 = [1, 2, 3, 4]
  
// Checking for Equal Value 
console.log("The Values are Equal : "
        +_.isEqual(val1,val2));

chevron_right


Output:

The Values are Equal : true

Example 3: For strings: 

Javascript

filter_none

edit
close

play_arrow

link
brightness_4
code

// Defining Lodash variable 
const _ = require('lodash'); 
  
var val1 = "gfg"
  
var val2 = "gfg"
  
// Checking for Equal Value 
console.log("The Values are Equal : "
        +_.isEqual(val1,val2));

chevron_right


Output:



The Values are Equal : true

Example 4: For numbers: 

Javascript

filter_none

edit
close

play_arrow

link
brightness_4
code

// Defining Lodash variable 
const _ = require('lodash'); 
  
var val1 = 1
  
var val2 = 1
  
// Checking for Equal Value 
console.log("The Values are Equal : "
        +_.isEqual(val1,val2));

chevron_right


Output:

The Values are Equal : true

Example 5: 

Javascript

filter_none

edit
close

play_arrow

link
brightness_4
code

// Defining Lodash variable 
const _ = require('lodash'); 
  
var val1 = 222
  
var val2 = 323
  
// Checking for Equal Value 
console.log("The Values are Equal : "
        +_.isEqual(val1,val2));

chevron_right


Output:

The Values are Equal : false

full-stack-img

My Personal Notes arrow_drop_up
Recommended Articles
Page :