Lodash _.isEqualWith() Method
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
const _ = require( 'lodash' );
function portal(val) {
return /^G(?:fG|eeksforGeeks)$/.test(val);
}
function customizer(objectValue, otherValue) {
if (portal(objectValue) && portal(otherValue)) {
return true ;
}
}
let val = [ 'GeeksforGeeks' , 'CS-portal' ];
let otherval = [ 'GfG' , 'CS-portal' ];
let result = _.isEqualWith(val, otherval, customizer);
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
const _ = require( 'lodash' );
function portal(val) {
return /^G(?:fG|eeksforGeeks)$/.test(val);
}
function customizer(objectValue, otherValue) {
if (portal(objectValue) && portal(otherValue)) {
return true ;
}
}
let val = [ 'GeeksforGeeks' , 'CS-portal' ];
let otherval = [ 'GfG' , 'portal' ];
let result = _.isEqualWith(val, otherval, customizer);
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
const _ = require( 'lodash' );
function gfg(val) {
return val;
}
function intg(x, y) {
if (gfg(x) === gfg(y)) {
return true ;
}
}
let result = _.isEqualWith( 'gf' , 'gfg' , intg);
console.log(result);
|
Output:
false
Reference: https://lodash.com/docs/4.17.15#isEqualWith
Last Updated :
31 Oct, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...