Using a string to access a variable

后端 未结 3 462
难免孤独
难免孤独 2021-01-14 17:23

I currently have a Javascript function that uses a string to reference an object name and acces its properties. I\'m currently using eval() to get the the desired effect whi

3条回答
  •  难免孤独
    2021-01-14 17:37

    eval("myTestObject[\"item1\"") should do the trick, as myTestObject.item1 is shorthand for myTestObject["item1"]

    How do I reference an object dynamically?

提交回复
热议问题