2

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"
  }
}
ChaosPandion
  • 77,506
  • 18
  • 119
  • 157
primary0
  • 1,180
  • 1
  • 10
  • 21

2 Answers2

5

You'll want to use bracket notation:

var my_hash = {};
my_hash[my_param] = "foobar";
ChaosPandion
  • 77,506
  • 18
  • 119
  • 157
2
var my_hash = {};
my_hash[my_param] = 'foobar';

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

alex
  • 479,566
  • 201
  • 878
  • 984