I am doing the filter declaring a final
array. it seems that the codes are much. it can be shortened?
code :
const lookup = [
{
hfsUserCountryId: 2895,
countryCd: 140,
},
{
hfsUserCountryId: 2895,
countryCd: 1301,
},
];
const countries = [
{
"defaultOrder" : 0,
"label" : "data.Code.Country_Cd.Code_Desc.US",
"codeId" : 140,
"code" : "US",
"codeDesc" : "USA",
"codeQualifier" : "Country_Cd"
},
{
"defaultOrder" : null,
"label" : "data.Code.Country_Cd.Code_Desc.AE",
"codeId" : 1301,
"code" : "AE",
"codeDesc" : "United Arab Emirates",
"codeQualifier" : "Country_Cd"
},
{
"defaultOrder" : 1,
"label" : "data.Code.Country_Cd.Code_Desc.AL",
"codeId" : 1086,
"code" : "AL",
"codeDesc" : "Albania",
"codeQualifier" : "Country_Cd"
}, {
"defaultOrder" : null,
"label" : "data.Code.Country_Cd.Code_Desc.DZ",
"codeId" : 2615,
"code" : "DZ",
"codeDesc" : "Algeria",
"codeQualifier" : "Country_Cd"
}
];
const final = []
const result = countries.filter(item =>{
const {codeId} = item;
const r = lookup.filter(look => {
if( look.countryCd === codeId){
final.push(item)
}
} );
});
console.log('reuslt', final);