主题
unionBy
js
_.unionBy([arrays], [iteratee=_.identity])
此方法与 _.union
类似,不同之处在于它接受 iteratee
,调用该方法可生成计算唯一性的标准。结果值从出现该值的第一个数组中选择。迭代器使用一个参数调用:(value)。
¥This method is like _.union
except that it accepts iteratee
which is invoked for each element of each arrays
to generate the criterion by which uniqueness is computed. Result values are chosen from the first array in which the value occurs. The iteratee is invoked with one argument: (value).
新增于
¥Since
4.0.0
参数
¥Arguments
[arrays]
(...数组):要检查的数组。¥
[arrays]
(...Array): The arrays to inspect.[iteratee=_.identity]
(函数):每个元素调用迭代器。¥
[iteratee=_.identity]
(Function): The iteratee invoked per element.
返回
¥Returns
(数组):返回新的组合值数组。
¥(Array): Returns the new array of combined values.
示例
¥Example
js
_.unionBy([2.1], [1.2, 2.3], Math.floor);
// => [2.1, 1.2]
// The `_.property` iteratee shorthand.
_.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
// => [{ 'x': 1 }, { 'x': 2 }]