爲什麼這不起作用?爲什麼我可以用[val]訪問js對象但不是.val?
function phoneticLookup(val) {
var result = "";
var lookup = {
"alpha": "Adams",
"bravo": "Boston",
"charlie": "Chicago",
"delta": "Denver",
"echo": "Easy",
"foxtrot": "Frank"
};
result = lookup.val;
return result;
}
phoneticLookup("charlie");
但這確實
function phoneticLookup(val) {
var result = "";
var lookup = {
"alpha": "Adams",
"bravo": "Boston",
"charlie": "Chicago",
"delta": "Denver",
"echo": "Easy",
"foxtrot": "Frank"
};
result = lookup[val];
return result;
}
phoneticLookup("charlie");
爲什麼在訪問對象時使用點操作不能與動態輸入工作?
'lookup.val'相當於'lookup [「val」]' –