Skip to content

uniqWith

js
_.uniqWith(array, [comparator])

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

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

新增于

¥Since

4.0.0

参数

¥Arguments

  1. array (数组):要检查的数组。

    ¥array (Array): The array to inspect.

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

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

返回

¥Returns

(数组):返回新的重复释放数组。

¥(Array): Returns the new duplicate free array.

示例

¥Example

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

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

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