I have an object called themesData
:
var themesData = {}
themesData.a = { key: "value" };
themesData.b = { key: "another value"};
...and I want to access one of the members by its name. I get a string which contains either "a" or "b" and I want to get the appropriate member's value.
I'd be happy to get some help on that.
I have an object called themesData
:
var themesData = {}
themesData.a = { key: "value" };
themesData.b = { key: "another value"};
...and I want to access one of the members by its name. I get a string which contains either "a" or "b" and I want to get the appropriate member's value.
I'd be happy to get some help on that.
Share Improve this question edited May 15, 2014 at 13:18 Germstorm 9,84914 gold badges69 silver badges83 bronze badges asked Jan 25, 2010 at 14:09 NirNir 4,0138 gold badges39 silver badges53 bronze badges2 Answers
Reset to default 10themesData["a"].key
does what you need and is equivalent to themesData.a.key
, still the "array index style" notation allows you to dynamically generate index names.
You can do it in this way:
var member="a"; //or B
var rightMember=themesData[member].key;