Lodash/JavaScript:比较两个集合并返回差异 [英] Lodash / javascript : Compare two collections and return the differences

查看:95
本文介绍了Lodash/JavaScript:比较两个集合并返回差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个对象数组:

表中的元素不是原始值,而是复杂的对象.

the element of my table are not primitive value, but complexe objects.

array1 = [obj1,obj2,obj3,obj4]
array2 = [obj5,obj5,obj6,obj7]

我想比较两个数组,看看array2的元素已经存在于array1中,然后创建一个新的差异数组.

I would like to compare two arrays and see of the elements of array 2 are already present in array1 then create a new array of the difference.

有什么建议吗?

推荐答案

var presents = _.intersectionWith(array1, array2, _.isEqual);
var dif = _.differenceWith(array1, array2, _.isEqual);

这篇关于Lodash/JavaScript:比较两个集合并返回差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆