0

我遇到了这个问题。

//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
4

1 回答 1

1

与您设置它的方式相同:

alert(myObject[myArray[0]])
于 2012-10-26T17:01:04.563 回答