javascript access object property as variable 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]); //Dynamically access object property with bracket notation
Example 2: Accessing Object Properties with Variables
var dogs = {
Fido: "Mutt", Hunter: "Doberman", Snoopie: "Beagle"
};
var myDog = "Hunter";
var myBreed = dogs[myDog];
console.log(myBreed); // "Doberman"