Lodash - isEqualWith 方法

语法

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

此方法与 _.isEqual 类似,不同之处在于它接受调用来比较值的 customizer。如果 customizer 返回未定义,则由该方法处理比较。customizer 最多使用六个参数调用:(objValue, othValue [, index|key, object, other, stack])。

参数

  • value (*) − 要比较的值。

  • other (*) − 要比较的其他值。

  • [customizer] (函数) −自定义比较的函数。

输出

  • (boolean) − 如果值相等则返回 true,否则返回 false。

示例

var _ = require('lodash');
function isGreeting(value) {
    return /^h(?:i|ello)$/.test(value);
}
function customizer(objValue, othValue) {
    if (isGreeting(objValue) && isGreeting(othValue)) {
        return true;
    }
}
var array = ['hello', 'goodbye'];
var other = ['hi', 'goodbye'];

console.log(_.isEqualWith(array, other, customizer));

将上述程序保存在tester.js中。运行以下命令执行此程序。

命令

\>node tester.js

输出

true

lodash_lang.html