我从服务器获取了两个对象数组,就像这样:
var duplicateTestData = [
{
licenseId: 'xxx',
batchId: '123',
reportDate: Fri Dec 11 2015 00:00:00 GMT+0530 (India Standard Time)
},
{
licenseId: 'yyy',
batchId: '124',
reportDate: Fri Dec 11 2015 00:00:00 GMT+0530 (India Standard Time)
},
{
licenseId: 'aaa',
batchId: '145',
reportDate: Fri Dec 11 2015 00:00:00 GMT+0530 (India Standard Time)
}
];
var finalResult = [
{
reportDate: Fri Dec 11 2015 00:00:00 GMT+0530 (India Standard Time),
license: {},
testType: 'P1',
productType: 'Flower',
batchId: '123',
licenseId: 'xxx',
createType: 'DataUpload'
},
{
reportDate: Fri Dec 11 2015 00:00:00 GMT+0530 (India Standard Time),
testType: 'P1',
productType: 'Flower',
batchId: '124',
licenseId: 'yyy',
createType: 'DataUpload'
},
{
reportDate: Fri Dec 11 2015 00:00:00 GMT+0530 (India Standard Time),
testType: 'P1',
productType: 'Flower',
batchId: '145',
licenseId: 'aaa',
createType: 'DataUpload'
},
{
reportDate: Fri Dec 14 2015 00:00:00 GMT+0530 (India Standard Time),
testType: 'P1',
productType: 'Flower',
batchId: '145',
licenseId: 'zzz',
createType: 'DataUpload'
}
]
我正在尝试从
finalResult
对象中仅获取不匹配的对象,最终结果将如下所示:[
{
reportDate: Fri Dec 14 2015 00:00:00 GMT+0530 (India Standard Time),
testType: 'P1',
productType: 'Flower',
batchId: '145',
licenseId: 'zzz',
createType: 'DataUpload'
}
]
我正在尝试这个,但是没有得到正确的结果:
for(var j=0;j < duplicateTestData.length;j++){
for (var i = 0; i < finalResult.length; i++) {
if (
(finalResult[i].licenseId == duplicateTestData[j].licenseId) &&
(finalResult[i].reportDate == duplicateTestData[j].reportDate) &&
(finalResult[i].batchId == duplicateTestData[j].batchId)
) {
finalResult.splice(i, 1);
break;
}
}
}
console.log(finalResult);