get variable from object javascript code example
Example 1: Accessing Object Properties with Variables
var dogs = {
Fido: "Mutt", Hunter: "Doberman", Snoopie: "Beagle"
};
var myDog = "Hunter";
var myBreed = dogs[myDog];
console.log(myBreed);
Example 2: Accessing Object Properties with Variables
var someObj = {
propName: "John"
};
function propPrefix(str) {
var s = "prop";
return s + str;
}
var someProp = propPrefix("Name");
console.log(someObj[someProp]);
Example 3: javascript object
const object = {
something: "something";
}