企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
## differenceWith + [link](./differenceWith "Link to this entry.") + [source](https://github.com/lodash/lodash/blob/4.5.0正式版/lodash.src.js#L5648 "View in source.") + [npm](https://www.npmjs.com/package/lodash.differencewith "See the npm package.") ``` _.differenceWith(array, [values], [comparator]) ``` 这个方法类似 `_.difference`,除了它接受一个 comparator 调用每一个数组元素的值。 comparator 会传入2个参数:(arrVal, othVal)。 ### 参数 1. array (Array) 需要处理的数组 2. [values] (...Array) 用于对比差异的数组 3. [comparator] (Function) 这个函数会处理每一个元素 ### 返回值 (Array) 返回一个差异化后的新数组 ### 示例 ``` var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]; _.differenceWith(objects, [{ 'x': 1, 'y': 2 }], _.isEqual); // => [{ 'x': 2, 'y': 1 }] ```