我遇到这个问题。
//Targeting a property of an object using an array
myArray = ["property0","property1","property2","property3"];
myObject = {};
myObject[myArray[0]] = "value0";
//accepts this line as myObject.property0 = "value0";
alert(myObject.myArray[0]); // <-- how can I target this using my Array?
//this fails
// alert(myObject.property0);
//this works
答案 0 :(得分:1)
与设置方式相同:
alert(myObject[myArray[0]])