復制代碼 代碼如下:
//js中的數組可以以鍵值對的方式存在
var arr = new Array();
arr["A"] = "boss";
arr["B"] = "Emp";
for (var m in arr) {
document.write(arr[m] + " ");
}
var person = new Object();
person["name"] = "xiaoli";
person["age"] = "18";
person["salary"] = "1888.9";
for (var p in person) {
document.write(person[p] + "<br>");
}
//測試使用有age屬性呢?
if (typeof person["age"] == "undefined") {
document.write("no");
}