-1

I have

object.name = 'foo';
var value = 'bar';
...
var params = { object.name : 1, value : value};

I want a result equivalent to

var params = { foo : 1, value : bar };

what can I do?

Andy
  • 61,948
  • 13
  • 68
  • 95
Lokomotywa
  • 2,624
  • 8
  • 44
  • 73
  • 1
    What have you already tried? BTW, `{ object.name : 1, value : value}` doesn't make much sense. There's also no JSON here. – Andy Sep 12 '14 at 09:21

1 Answers1

0

Objects are sometimes called associative arrays, since each property is associated with a `string value that can be used to access it.

Try using [] to set object property -

object.name = 'foo';
var value = 'bar';
var params = { value:value};
params[ object.name] = 1;

Output:- {value: "bar", foo: 1}

vikrant singh
  • 2,091
  • 1
  • 12
  • 16