Il existe les tableaux suivants
const arr = [
{ city: '北京', cityid: '001' },
{ city: '上海', cityid: '002' },
{ city: '广州', cityid: '003' },
{ city: '深圳', cityid: '004' }
];
La première consiste à trouver l'enregistrement correspondant à city="Beijing"
const obj=arr.find(item=>item.city==='北京')
Ensuite, affichez le cityid de cet enregistrement
const cityid=obj.cityid
Dans une application normale, le code complet de la requête de ville et de la valeur de passage de la fonction de continuation est le suivant
const arr = [
{ city: '北京', cityid: '001' },
{ city: '上海', cityid: '002' },
{ city: '广州', cityid: '003' },
{ city: '深圳', cityid: '004' }
];
function citysearch(e){
const duixiang=arr.find(item=>item.city==e)
return duixiang.cityid
}
console.log(citysearch('北京'))//001