[removed] access to an object's member by name

前端 未结 2 1210
面向向阳花
面向向阳花 2020-12-11 18:21

I have an object called themesData:

var themesData = {}
themesData.a = { key: \"value\" }; 
themesData.b = { key: \"another value\"};

相关标签:
2条回答
  • 2020-12-11 18:43

    themesData["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.

    0 讨论(0)
  • 2020-12-11 19:07

    You can do it in this way:

    var member="a"; //or B
    var rightMember=themesData[member].key;
    
    0 讨论(0)
提交回复
热议问题