JS Calling Object Property by Variable

后端 未结 1 1378
花落未央
花落未央 2021-01-28 11:07

When I have an object and I want to refer to a property within it, I can use e.g.

objectName.propertyName 

and when I have a \"subproperty\" I

相关标签:
1条回答
  • 2021-01-28 11:13

    Use the bracket notation:

    var myvar = 'qwertz';
    var result = objectName[myvar].propertyName; 
    // equivalent to objectName.qwertz.propertyName
    
    0 讨论(0)
提交回复
热议问题