I have a simple simulated aarray with two elements:
bowl["fruit"]="apple";
bowl["nuts"]="brazilian";
I can access the value with an event like this:
onclick="testButton00_('fruit')">with `testButton00_`
function testButton00_(key){
var t = bowl[key];
alert("testButton00_: value = "+t);
}
However whenever I try to access the aarray from within code with a key that is just a non-explicit string I get undefined. Do I have somehow have to pass the parameter with the escaped 'key'. Any ideas? tia.
I am not sure I understand you, you can make sure the key is a string like this
Or you can check if the key exists:
However I don't think you have posted the non working code?
The key can be a dynamically computed string. Give an example of something you pass that doesn't work.
Given:
You can say:
Or:
Or even:
Or if you really want to:
Those all have the same effect on the
bowl
object. And then you can use the corresponding patterns to retrieve values:You could use JSON if you dont want to escape the key.