I have a javascript object like this
var obj={
a:{x: "someValue", y:"anotherValue"},
b:{x: "bValue", y:"anotherbValue"}
};
and I am trying to reference it like this
function(some_value){
alert("some_value is " + some_value + " with type " + typeof some_value);
// prints some_value is a with type string
var t;
t=obj[some_value]["x"]; // doesn't work
some_value="a";
t=obj[some_value]["x"]; // this does work
t=obj["a"]["x"]; // and so does this
}
I would really like understand what is going on here . Ideally I'd like to reference my object with the value passed to the function. Thanks
some_valueis indeed"a", thent=obj[some_value]["x"];will work.