<script type= "Text/javascript" >
var dic = new Array ();//Note that its type is array
dic["ZS"] = "Zhang San";
dic["ls"] = "John Doe";
Dic["ww"] = "Harry";
Dic["ZL"] = "Zhao Liu";
Alert (dic["ZS"]);
alert (DIC.LS);///The value of the dictionary can also be read in a dot way
Traverse Dictionary
var output = "";
for (var key in DiC) {
if (output = = "") {
output = Dic[key];
}
else {
Output + = "|" + Dic[key];
}
}
alert (output);
//Special dictionary, note that its type is array
var dic2 = ["A", "B", "C", "D"]; //It's key is 0,1,2,3
Traverse Dictionary
for (var key in Dic2) {
Alert (Dic2[key]);
}
//Dictionary simplified style, note that its type is not an array, but a JSON object
var dic3 = {"Zs": "31", "ls": "Li 41", "WW": "Wang 51"};
var output = "";
for (var key in dic3) {
if (output = = "") {
output = Dic3[key];
}
else {
Output + = "|" + Dic3[key];
}
}
alert (output);
</script>
JavaScript dictionary Operations