Summary of various methods to solve JavaScript Array problems. Many blueidea experts jointly created a1 = ['020', '021 ',.......... '025',...];
A2 = ['shanghai', 'tianjin ',... Nanjing,...];
The length is the same as the length, and corresponds to one by one. How can we get the a2 Nanjing in a1?
I tried a method, but I used a lot of eval and a loop, and I don't feel very good:
Script var a1 = ['020', '021 ', '025'], a2 = ['shanghai', 'tianjin', 'nanjing ']; var obj = function () {for (var I = 0; I
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]
As long as you confirm that the number is at three places ,,
Then OK!
Script var a1 = ['020', '021 ', '025', '000000'], a2 = ['shanghai', 'tianjin', 'nanjing ', 'xp ']; alert (a2 [(a1.join (). indexOf ('021 ')/4]); script
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]
This is an array implementation method.
Script var a1 = ['020', '021 ', '025'], a2 = ['shanghai', 'tianjin', 'nanjing ']; function getCity (n) {for (var I = 0, l = a1.length; I <l; I ++) if (n = a1 [I]) return a2 [I];} alert (getCity ("025") script
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]
Tips
If I complete similar functions, I will not select an array;
<Script type = "text/javascript"> var pros = {'021 ': 'shanghai', 'o22': 'beijing', 'o23 ': 'shenzhen'} alert (pros ['021 ']) script
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]