如何从jsonArray节点js java脚本获取匹配记录

时间:2018-02-23 08:55:15

标签: javascript node.js

jsonArray

[ { serial: '111',
    certificateNumber: 'CCT1',
    calibrationDate: '2018-01-02',
    gaugeDescription: 'newR',
    certificateName: '111.png',
    email: 'chetde@dev.com',
    dueDate: '2018-02-03' 
 },
  { serial: '222',
    certificateNumber: 'CCT2',
    calibrationDate: '2018-02-14',
    gaugeDescription: 'newRR',
    certificateName: '222.png',
    email: 'chetaayade@devcom',
    dueDate: '2018-01-16' 
},
  { serial: '333',
    certificateNumber: 'CCT3',
    calibrationDate: '2018-01-08',
    gaugeDescription: 'Records',
    certificateName: '333.png',
    email: 'chetan@dev.com',
    dueDate: '2018-01-18' } 
]

Uploded Docs

[ '333.png', '222.png' ]

如何按上传文档进行过滤

3 个答案:

答案 0 :(得分:2)

尝试以下(使用filter

var arr = [.....]; // your array
var uploadedDocs = [ '333.png', '222.png' ];

arr = arr.filter(function(item){
    return uploadedDocs.indexOf(item.certificateName) !== -1;
});

答案 1 :(得分:2)

只需使用filterincludes

即可
var uploadedDocs = [ '333.png', '222.png' ];
var output = jsonArray.filter( s => uploadedDocs.includes( s.certificateName ) );

答案 2 :(得分:0)

使用filter(item)indexOf()函数:

var uploadedDocs = [ '333.png', '222.png' ];
var filteredDocs = jsonArray.filter(item => item.indexOf(uploadedDocs) !== -1);