4

I have an array of objects and I'm looking to use google closure. I need to convert some dot notation to bracket notation.

At the moment, I'm accessing properties in a loop like this:

TheArray[i].MyProp1;
TheArray[i].MyProp2;

When I write

TheArray[i].['MyProp1'];

it doesn't convert. How do I do this conversion to bracket notation in arrays of objects.

2
  • This issue comes up about 100x per day, there has to be a resource online that can properly describe the array-access concept to beginners. Commented Mar 7, 2012 at 18:29
  • @zzzzBov: yea, I seo'ed the question's URL. Should be fixed:) You can upvote the question if you want to help. Commented Mar 7, 2012 at 19:29

2 Answers 2

7

Drop the dot.

It should just be TheArray[i]['MyProp1'];

Sign up to request clarification or add additional context in comments.

Comments

0

The brackets directly translate to the dot notation - you're accessing a member of the object.

TheArray[i]['MyProp1']

Comments

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.