javascript get object value dynamically code example
Example 1: javascript dynamically access object property
var person ={"first_name":"Billy","last_name":"Riley"};
var property_name="first_name";
alert(person[property_name]);
Example 2: dynamic properties instead javascript
var foo = { pName1 : 1, pName2 : [1, {foo : bar }, 3] , ...}
var name = "pName"
var num = 1;
foo[name + num];
var a = 2;
var b = 1;
var c = "foo";
foo[name + a][b][c];
Example 3: javascript get object value dynamically
var something = {
bar: 'foo'
};
var foo = 'bar';
console.log(something[foo]);
console.log(something.bar)