🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
## uniqWith + [link](./uniqWith "Link to this entry.") + [source](https://github.com/lodash/lodash/blob/4.5.0正式版/lodash.src.js#L6900 "View in source.") + [npm](https://www.npmjs.com/package/lodash.uniqwith "See the npm package.") ``` _.uniqWith(array, [comparator]) ``` 这个方法类似 `_.uniq`,除了它接受一个 `comparator` 来比较计算唯一性。 `comparator` 会传入2个参数:(arrVal, othVal) ### 参数 1. array (Array) 需要处理的数组 2. [comparator] (Function) 这个函数会处理每一个元素 ### 返回值 (Array) 返回不重复的数组 ### 示例 ``` 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 }] ```