多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
## unionWith + [link](./unionWith "Link to this entry.") + [source](https://github.com/lodash/lodash/blob/4.5.0正式版/lodash.src.js#L6833 "View in source.") + [npm](https://www.npmjs.com/package/lodash.unionwith "See the npm package.") ``` _.unionWith([arrays], [comparator]) ``` 这个方法类似 `_.union`, 除了它接受一个 comparator 调用每一个数组元素的值。 comparator 会传入2个参数:(arrVal, othVal)。 ### 参数 1. [arrays] (...Array) 需要处理的数组队列 2. [comparator] (Function) 这个函数会处理每一个元素 ### 返回值 (Array) 返回处理好的数组 ### 示例 ``` var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]; var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }]; _.unionWith(objects, others, _.isEqual); // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }] ```