var animals = {DOGS: 10, CATS: 1, RATS: 20, COWS: 0};
console.log(animals.DOGS); //output is 10
Very simple - I can access the value of DOGS by referencing it directly.
However I want to use a dynamic variable like the following:
var dynamicaccess = "CATS";
console.log(animals.dynamicaccess); //output is undefined
How come I am getting undefined? To a noob like me this seems really straightforward and should work! I've googled and there's not much reference to this, as apparently it should work! (Tried the code using Firefox and using jsfiddle)