I need to reference my object as a string but I am having issues.
ideally I would like this to work ['mystring'].myproperty; but obviously this wont work.
Is there another way besides the options below?
// auto generated ecample/////////////
var mystring = {
myproperty :'test'
}
/////////////////////////////////////
var optionA =mystring.myproperty; // works
var optionB = window['mystring'].myproperty; //gives issues
var optionC = eval('mystring').myproperty; //gives issues
var optionD = ['mystring'].myproperty; // wont work
optionCno use; overkill.optionDyou're creating an array with one string inside, and the array doesn't have amypropertymethod. So use A or B, those are correct.mystringis not property of thewindowobjectvar MY = { mystring: { myproperty: 'test' } }; MY['mystring'].myproperty