Open In App

Lodash _.isEqualWith() Method

Improve
Improve
Like Article
Like
Save
Share
Report

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

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

Return Value:

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

Example 1: In this example, we are checking whether the given two arrays are equal or not by the use of the Lodash _isEqualWith() method.

Javascript




// 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
let val = ['GeeksforGeeks', 'CS-portal'];
let otherval = ['GfG', 'CS-portal'];
 
// Calling isEqualWith() method with all
// its parameter
let result = _.isEqualWith(val, otherval, customizer);
 
// Displays output
console.log(result);


Output:

true

Example 2: In this example, we are checking whether the given two arrays are equal or not by the use of the Lodash _isEqualWith() method.

Javascript




// 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
let val = ['GeeksforGeeks', 'CS-portal'];
let otherval = ['GfG', 'portal'];
 
// Calling isEqualWith() method with all
// its parameter
let result = _.isEqualWith(val, otherval, customizer);
 
// Displays output
console.log(result);


Output:

false

Example 3: In this example, we are checking whether the given two arrays are equal or not by the use of the Lodash _isEqualWith() method.

Javascript




// 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);


Output:

false

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



Last Updated : 31 Oct, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads