如何使用变量a
的值作为查找属性的键?我想能够这样说:b["whatever"]
,并返回20:
var a = "whatever";
var b = {a : 20}; // Want this to assign b.whatever
alert(b["whatever"]); // so that this shows 20, not `undefined`
我想问一下,在创建b
的过程中,是否可以让其包含"whatever":20
而不是a:20
,其中"whatever"本身是一个变量。也许可以使用eval
吗?