Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/376.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript:访问对象';按姓名排列的成员_Javascript - Fatal编程技术网

Javascript:访问对象';按姓名排列的成员

Javascript:访问对象';按姓名排列的成员,javascript,Javascript,我有一个名为themesData的对象: var themesData = {} themesData.a = { key: "value" }; themesData.b = { key: "another value"}; …我想通过它的名字访问其中一个成员。我得到一个包含“a”或“b”的字符串,我想得到相应成员的值 我很高兴能在这方面得到一些帮助。themesData[“a”].key做了您需要的事情,相当于themesData.a.key,但“数组索引样式”表示法允许您动态生成索引名

我有一个名为
themesData
的对象:

var themesData = {}
themesData.a = { key: "value" }; 
themesData.b = { key: "another value"};
…我想通过它的名字访问其中一个成员。我得到一个包含“a”或“b”的字符串,我想得到相应成员的值


我很高兴能在这方面得到一些帮助。

themesData[“a”].key
做了您需要的事情,相当于
themesData.a.key
,但“数组索引样式”表示法允许您动态生成索引名。

您可以通过以下方式完成:

var member="a"; //or B
var rightMember=themesData[member].key;