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
Post a Comment