主题
uniqBy
js
_.uniqBy(array, [iteratee=_.identity])
此方法与 _.uniq
类似,不同之处在于它接受 iteratee
,调用 array
中的每个元素生成唯一性计算标准。结果值的顺序由它们在数组中出现的顺序决定。迭代器使用一个参数调用:(value)。
¥This method is like _.uniq
except that it accepts iteratee
which is invoked for each element in array
to generate the criterion by which uniqueness is computed. The order of result values is determined by the order they occur in the array. The iteratee is invoked with one argument: (value).
新增于
¥Since
4.0.0
参数
¥Arguments
array
(数组):要检查的数组。¥
array
(Array): The array to inspect.[iteratee=_.identity]
(函数):每个元素调用迭代器。¥
[iteratee=_.identity]
(Function): The iteratee invoked per element.
返回
¥Returns
(数组):返回新的重复释放数组。
¥(Array): Returns the new duplicate free array.
示例
¥Example
js
_.uniqBy([2.1, 1.2, 2.3], Math.floor);
// => [2.1, 1.2]
// The `_.property` iteratee shorthand.
_.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
// => [{ 'x': 1 }, { 'x': 2 }]