JavaScript dictionary Operations

Source: Internet
Author: User

<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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.