javascript - Dynamically access object property using variable -


i'm trying access property of object using dynamic name. possible?

const = { bar: "foobar!" }; const foo = 'bar'; something.foo; // idea access something.bar, getting "foobar!" 

there two ways access properties of object:

  • dot notation: something.bar
  • bracket notation: something['bar']

the value between brackets can expression. therefore, if property name stored in variable, have use bracket notation:

var foo = 'bar' something[foo] 

Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -