Skip to content

xorWith

js
_.xorWith([arrays], [comparator])

此方法与 _.xor 类似,不同之处在于它接受 comparator,调用该方法可比较 arrays 的元素。结果值的顺序由它们在数组中出现的顺序决定。比较器使用两个参数调用:(arrVal, othVal)。

¥This method is like _.xor except that it accepts comparator which is invoked to compare elements of arrays. The order of result values is determined by the order they occur in the arrays. The comparator is invoked with two arguments: (arrVal, othVal).

新增于

¥Since

4.0.0

参数

¥Arguments

  1. [arrays] (...数组):要检查的数组。

    ¥[arrays] (...Array): The arrays to inspect.

  2. [comparator] (函数):每个元素调用的比较器。

    ¥[comparator] (Function): The comparator invoked per element.

返回

¥Returns

(数组):返回新的过滤值数组。

¥(Array): Returns the new array of filtered values.

示例

¥Example

js
var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];

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

Lodash v4.17 中文网 - 粤ICP备13048890号