a1=['020','021',..........'025',..........];
a2=[' Shanghai','Tianjin',.........'Nanjing',..........];
length is the same length and corresponds one to one. How to get 025 in a1 Corresponding to Nanjing of a2?
I thought of a way, but it used a lot of evals and loops, which didn’t feel very good:
]
As long as you are sure The numbering position is three digits,
and then it’s ok!
If you need to introduce external Js, you need to refresh to execute
]
[Ctrl A Select all Note:
If you need to introduce external Js, you need to refresh to execute
]
[Ctrl A Select all Note:
If you need to introduce external Js, you need to refresh to execute
]
<script>
var a1=['020','021','025'],a2=['上海','天津','南京'];
var obj=function(){
for(var i=0;i<a1.length;i++){
eval("this.a"+a1[i]+"='"+a2[i]+"';")
}
this.getA=function(m){
return (eval("this.a"+m))
}
}
var obj2=new obj;
alert(obj2.getA('025'))
</script><script>
var a1=['020','021','025','999'],a2=['上海','天津','南京','xpxp'];
alert(a2[(a1.join().indexOf('021'))/4]);
</script><script>
var a1=['020','021','025'],a2=['上海','天津','南京'];
function getCity(n){
for(var i=0, l=a1.length; i<l; i++)
if(n==a1[i])return a2[i];
}
alert(getCity("025"))
</script>