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

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

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

html - jQuery UI Sortable - Remove placeholder after item is dropped -