_.differenceBy()方法用于通过使用Iteratee函数在数组中的每个元素上进行迭代来从原始数组中删除值。与_.difference()函数几乎相同。
用法:
lodash.differenceBy(array, [values], [iteratee=_.identity])
参数:此函数接受上面提到的三个参数,并在下面进行描述
- array:这是要从中删除值的数组。
 - values:从原始数组中删除的是值数组。
 - Iteratee:这是对每个元素进行迭代的函数。
 
注意:如果未提供iteratee函数,则_.differenceBy()函数充当_.difference()函数。
返回值:该函数返回一个数组。
范例1:
Javascript
// Requiring the lodash library 
const _ = require("lodash"); 
  
// Ooriginal array 
let array1 = [1, 2, 3, 4.2] 
  
// Array to be subtracted 
let val = [2, 3, 3, 5] 
  
// New Array after _.differenceBy()  
// method where Math.double is the 
// comparable function 
let newArray = _.differenceBy( 
    array1, val, Math.double); 
  
// Printing the original array 
console.log("Before:", array1); 
  
// Printing the output 
console.log("After:", newArray);输出:

范例2:
Javascript
// Requiring the lodash library 
const _ = require("lodash"); 
  
// Original array 
let array1 = [1, 2, 3, 4.2] 
  
// Value array to be subtracted 
let val = [2, 3, 4, 5] 
  
// new Array after _.differenceBy() 
// method where Math.double is the 
// comparable function 
let newArray1 = _.differenceBy( 
    array1, val, Math.floor); 
  
// New Array after _.differenceBy function 
// where no comparable function is given 
let newArray2 = _.differenceBy(array1, val); 
  
// Printing the original array 
console.log("Before:", array1); 
  
// Nrinting the output 
console.log("When compare funct is given:",  
        newArray1); 
  
// Printing the output 
console.log("When compare funct is not given:",  
        newArray2);输出:

相关用法
- Lodash _.method()用法及代码示例
 - Lodash _.sneq()用法及代码示例
 - Lodash _.toQuery()用法及代码示例
 - Lodash _.uniqWith()用法及代码示例
 - Lodash _.xorWith()用法及代码示例
 - Lodash _.head()用法及代码示例
 - Lodash _.remove()用法及代码示例
 - Lodash _.pullAt()用法及代码示例
 - Lodash _.pullAll()用法及代码示例
 - Lodash _.pull()用法及代码示例
 - Lodash _.nth()用法及代码示例
 - Lodash _.takeRight()用法及代码示例
 - Lodash _.take()用法及代码示例
 - Lodash _.sortedLastIndex()用法及代码示例
 - Lodash _.fromPairs()用法及代码示例
 - Lodash _.differenceWith()用法及代码示例
 - Lodash _.castArray()用法及代码示例
 - Lodash _.cloneDeep()用法及代码示例
 - Lodash _.clone()用法及代码示例
 - Lodash _.sampleSize()用法及代码示例
 - Lodash _.find()用法及代码示例
 - Lodash _.zipWith()用法及代码示例
 - Lodash _.zipObject()用法及代码示例
 - Lodash _.xor()用法及代码示例
 
注:本文由纯净天空筛选整理自tarun007大神的英文原创作品 Lodash _.differenceBy() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
