admin管理员组文章数量:1431406
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']
本文标签: javascript dot notation to bracket notation in array of objectsStack Overflow
版权声明:本文标题:javascript dot notation to bracket notation in array of objects - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745578946a2664504.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论