How do I get string value of a parameter in to cre

2019-05-20 10:59发布

This question already has an answer here:

How do I get "my_param" as a string so that I can use it as a key in the has I am trying to create?

var my_function = function(my_param) {
  var my_hash = { 
    my_param: "foobar"
  }
}

2条回答
smile是对你的礼貌
2楼-- · 2019-05-20 11:27
var my_hash = {};
my_hash[my_param] = 'foobar';

This is bracket notation, where a.b = 'c' is the same as a['b'] = 'c'.

查看更多
贼婆χ
3楼-- · 2019-05-20 11:31

You'll want to use bracket notation:

var my_hash = {};
my_hash[my_param] = "foobar";
查看更多
登录 后发表回答