在UnderscoreJS中,有一种叫做_.difference的方法,它可以给出两个数组之间的区别。
但在我的例子中,我有两个不同的数组,如下所示:
阵列1:
var obj1 = [
{
id: 1,
name: 'abc-1',
lname: 'xyz-1',
phone: 'xxxxxx1',
company: 'Comp-1',
address: 'Address-1',
country: 'C-1',
securityNo: 'xxxx-1'
},
{
id: 2,
name: 'abc-2',
lname: 'xyz-2',
phone: 'xxxxxx2',
company: 'Comp-2',
address: 'Address-2',
country: 'C-2',
securityNo: 'xxxx-2'
},
{
id: 3,
name: 'abc-3',
lname: 'xyz-3',
phone: 'xxxxxx3',
company: 'Comp-3',
address: 'Address-3',
country: 'C-3',
securityNo: 'xxxx-3'
}]另一个数组只包含有限的属性:
阵列2:
var obj2 = [
{
id: 1,
name: 'abc-1',
lname: 'xyz-1'
},
{
id: 2,
name: 'abc-2',
lname: 'xyz-2'
}]现在,我想应用这两个数组之间的区别,例如:
_.difference(obj1, obj2);它应该给我第三个元素作为结果。
但我没有办法做到这一点。
发布于 2017-12-08 16:51:17
https://stackoverflow.com/questions/47595210
复制相似问题