3
rated 0 times
[
7]
[
4]
/ answers: 1 / hits: 45816
/ 13 Years ago, tue, april 12, 2011, 12:00:00
How can I use the value of the variable a
as a key to lookup a property? I want to be able to say: b[whatever]
and have this return 20:
var a = whatever;
var b = {a : 20}; // Want this to assign b.whatever
alert(b[whatever]); // so that this shows 20, not `undefined`
I am asking if it's possible during the creation of b
, to have it contain whatever:20
instead of a:20
where whatever is itself in a variable. Maybe an eval
could be used?
More From » dictionary