codecamp

lodash _.differenceWith

_.differenceWith(array, [values], [comparator])

这个方法类似_.difference ,除了它接受一个 comparator (注:比较器),它调用比较array,values中的元素。 结果值是从第一数组中选择。comparator 调用参数有两个:(arrVal, othVal)。Note: 不像_.pullAllWith, 这个方法会返回一个新数组。

引入版本

4.0.0

参数

  1. array (Array): 要检查的数组。
  2. [values] (...Array): 排除的值。
  3. [comparator] (Function): comparator 调用每个元素。

返回值

(Array): 返回一个过滤值后的新数组。

例子

var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
 _.differenceWith(objects, [{ 'x': 1, 'y': 2 }], _.isEqual);
// => [{ 'x': 2, 'y': 1 }]


lodash _.differenceBy
Lodash _.drop
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

Lodash 简介

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }