How to use the isEqualWith function from lodash

Find comprehensive JavaScript lodash.isEqualWith code examples handpicked from public code repositorys.

lodash.isEqualWith is a function that performs a deep comparison of two values, with the ability to customize the comparison logic.

186
187
188
189
190
191
192
193
194
195
module.exports.isDate              = _.isDate;
module.exports.isDecreasing        = _.isDecreasing;
module.exports.isElement           = _.isElement;
module.exports.isEmpty             = _.isEmpty;
module.exports.isEqual             = _.isEqual;
module.exports.isEqualWith         = _.isEqualWith;
module.exports.isError             = _.isError;
module.exports.isEven              = _.isEven;
module.exports.isFinite            = _.isFinite;
module.exports.isFloat             = _.isFloat;
fork icon19
star icon122
watch icon0

+ 92 other calls in file

422
423
424
425
426
427
428
429
430
431
432
433
434
console.log(isEmpty); // => true


const isEqual = _.isEqual({ 'a': 1 }, { 'a': 1 });
console.log(isEqual); // => true


const isEqualWith = _.isEqualWith({ 'a': 1 }, { 'a': 1 }, (a, b) => a === b);
console.log(isEqualWith); // => true


const isError = _.isError(new Error);
console.log(isError); // => true
fork icon0
star icon4
watch icon0

+ 15 other calls in file

How does lodash.isEqualWith work?

lodash.isEqualWith is a function that performs a deep comparison of two values, with the option to customize the comparison logic using a customizer function. The customizer function is called for each comparison and allows the user to handle specific cases.

678
679
680
681
682
683
684
685
686
687
    );
}

//  locate any matching action block
const actionBlock = submitConf.find(actionBlock =>
    _.isEqualWith(
        formData.value,
        actionBlock.value,
        self.actionBlockValueComparator
    )
fork icon0
star icon0
watch icon1

Ai Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
const _ = require("lodash");

const object1 = { x: 1, y: 2 };
const object2 = { x: 1, y: "2" };

const customizer = (value1, value2, key) => {
  // Compare the values of the "y" property as numbers
  if (key === "y") {
    return _.eq(Number(value1), Number(value2));
  }
  // Use the default comparison for all other properties
  return undefined;
};

const isEqual = _.isEqualWith(object1, object2, customizer);

console.log(isEqual); // output: true

In this example, lodash.isEqualWith is used to compare two objects object1 and object2. The function customizer is passed as the third argument to lodash.isEqualWith. The customizer function is used to compare the values of the "y" property as numbers instead of strings. The isEqual variable holds the result of the comparison between object1 and object2, which is true because the values of the "x" property are equal and the values of the "y" property are equal when compared as numbers.

Other functions in lodash

Sorted by popularity

function icon

lodash.get is the most popular function in lodash (7670 examples)