Lodash _.isEqualWith() 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 _.isEqualWith() method of Lang in lodash is similar to _.isEqual() method and the only difference is that it accepts customizer which is called in order to compare values. Moreover, if the customizer used here returns undefined then the comparisons are dealt by the method instead. 

Note: The customizer used here can be called with up to six arguments namely objValue, othValue, index|key, object, other, and stack.

Syntax:

_.isEqualWith(value, other, [customizer])

Parameters: This method accepts three parameters as mentioned above and described below:



  • value: It is the value to be compared.
  • other: It is the other value to be compared.
  • customizer: It is the function which is used to customize comparisons.

Return Value: This method returns true if the stated values are equivalent otherwise it returns false.

Example 1:

Javascript

filter_none

edit
close

play_arrow

link
brightness_4
code

// Requiring lodash library
const _ = require('lodash');
  
// Defining a function portal
function portal(val) {
  return /^G(?:fG|eeksforGeeks)$/.test(val);
}
   
// Defining customizer to compare values
function customizer(objectValue, otherValue) {
  if (portal(objectValue) && portal(otherValue)) {
    return true;
  }
}
  
// Initializing values
var val = ['GeeksforGeeks', 'CS-portal'];
var otherval = ['GfG', 'CS-portal'];
  
// Calling isEqualWith() method with all
// its parameter
let result = _.isEqualWith(val, otherval, customizer); 
  
// Displays output
console.log(result);

chevron_right


Output:

true

Example 2:

Javascript

filter_none

edit
close

play_arrow

link
brightness_4
code

// Requiring lodash library
const _ = require('lodash');
  
// Defining a function portal
function portal(val) {
  return /^G(?:fG|eeksforGeeks)$/.test(val);
}
   
// Defining customizer to compare values
function customizer(objectValue, otherValue) {
  if (portal(objectValue) && portal(otherValue)) {
    return true;
  }
}
  
// Initializing values
var val = ['GeeksforGeeks', 'CS-portal'];
var otherval = ['GfG', 'portal'];
  
// Calling isEqualWith() method with all
// its parameter
let result = _.isEqualWith(val, otherval, customizer); 
  
// Displays output
console.log(result);

chevron_right


Output:

false

Example 3:

Javascript

filter_none

edit
close

play_arrow

link
brightness_4
code

// Requiring lodash library
const _ = require('lodash');
  
// Defining a function gfg
function gfg(val) {
  return val;
}
  
// Defining customizer
function intg(x, y) {
 if (gfg(x) === gfg(y)){  
  return true;
   }
}
  
// Calling isEqualWith() method with all
// its parameter
let result = _.isEqualWith('gf', 'gfg', intg); 
  
// Displays output
console.log(result);

chevron_right


Output:

false

Reference: https://lodash.com/docs/4.17.15#isEqualWith

full-stack-img




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.