-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
  • 53,323
  • 11
  • 64
  • 89
Lokomotywa
  • 2,455
  • 7
  • 40
  • 66
  • 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,051
  • 1
  • 11
  • 15