0

I'm having trouble with this one.

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

1 Answer 1

1

The same way you set it:

alert(myObject[myArray[0]])
Sign up to request clarification or add additional context in comments.

1 Comment

Wow. Can't believe the answer was so easy. I was having a headache over this one. Thanks Alexei!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.