Lodash - isEqualWith 方法
語法
_.isEqualWith(value, other, [customizer])
此方法類似於 _.isEqual,但它接受 customizer,其用於比較值。如果 customizer 返回未定義,則改由方法處理比較。customizer 最多使用六個引數進行呼叫:(objValue, othValue [, index|key, object, other, stack]).
引數
value (*) − 要比較的值。
other (*) − 要比較的另一個值。
[customizer] (Function) − 用於自定義比較的函式。
輸出
(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.htm
廣告