使用array-Javascript的对象的目标属性
这个我有点麻烦使用array-Javascript的对象的目标属性,javascript,arrays,object,properties,target,Javascript,Arrays,Object,Properties,Target,这个我有点麻烦 //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
//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
//使用数组定位对象的属性
myArray=[“property0”、“property1”、“property2”、“property3”];
myObject={};
myObject[myArray[0]]=“value0”;
//接受此行作为myObject.property0=“value0”;
警报(myObject.myArray[0]);// 与设置的方式相同:
alert(myObject[myArray[0]])
哇!真不敢相信答案这么简单。这件事让我头疼。谢谢阿列克谢!