In JavaScript, I have a JSON Object. This JSON Object has many keys and I need to access one stored in as a String using the dot operator but am not sure how to do this.
For example, if I have the following JSON code:
"values" : [ { "prop0" : "h",
"prop1" : "pizza",
"prop2" : "2014-06-24T15:58:50Z",
"prop3" : ""
},
{ "prop0" : "paa",
"prop1" : "cat",
"prop2" : "2014-06-24T15:58:16Z",
"prop3" : "mouse"
}
]
and I want to access prop1 I would use the following JavaScript code:
values[0].prop1;
This works so long as I know that the property is called prop1. But I don't know what my properties will be called. I have a String that represents what, in this case, is prop1 or whatever the current property is, however I don't know how to use the dot operator with a String.
I would like something like:
values[0].myString;
But this does not work.
Is there a way to do what I am trying to achieve?