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.
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.
Share Improve this question asked Mar 7, 2012 at 18:27 frenchiefrenchie 52.1k117 gold badges320 silver badges528 bronze badges 2- This issue es up about 100x per day, there has to be a resource online that can properly describe the array-access concept to beginners. – zzzzBov 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. – frenchie Commented Mar 7, 2012 at 19:29
2 Answers
Reset to default 7Drop the dot.
It should just be TheArray[i]['MyProp1'];
The brackets directly translate to the dot notation - you're accessing a member of the object.
TheArray[i]['MyProp1']