标签:
<script type="text/javascript">
var dic = new Array(); //注意它的类型是Array
dic["zs"] = "张三";
dic["ls"] = "李四";
dic["ww"] = "王五";
dic["zl"] = "赵六";
//alert(dic["zs"]);
//alert(dic.ls); //用点的方式也可以读取字典的值
//遍历字典
var output = "";
for (var key in dic) {
if (output == "") {
output = dic[key];
}
else {
output += "|" + dic[key];
}
}
//alert(output);
//特殊的字典,注意它的类型是Array
var dic2 = ["a", "b", "c", "d"]; //它的key是 0,1,2,3
//遍历字典
for (var key in dic2) {
//alert(dic2[key]);
}
//字典的简化风格方式,注意它的类型就不是Array了,而是Json对象
var dic3 = { "zs": "张三1", "ls": "李四1", "ww": "王五1" };
var output = "";
for (var key in dic3) {
if (output == "") {
output = dic3[key];
}
else {
output += "|" + dic3[key];
}
}
alert(output);
</script>
标签:
原文地址:http://www.cnblogs.com/mfc-itblog/p/5577096.html