在一个数组内查找符合某个条件的另一个数组里的元素(在数据字典里,找到符合某些value的label)
demo
const { log } = console
const findLabeInDict = function (dataAr,currentArr) {
if (currentArr && currentArr.length > 0 && dataArr && dataArr.length > 0) {
return dataArr.filter(e => currentArr.includes(e['value'])).map(item=>item['label']);
}
return [];
}
const currentArr = [14, 15]
let dataArr = [{
label: 'lilei',
value: 13,
gender: '1'
},
{
label: 'lilei2',
value: 14,
gender: '1'
},
{
label: 'hanmm',
value: 15,
gender: '0'
},
{
label: 'json',
value: 16,
gender: '1'
}]
log(findLabeInDict(dataArr,currentArr))