0

The way I usually do that,

var update = {};
update[name] = data;
update.resolved = true;

where, name is a variable.

I assume that's not the most efficient way of initialization, but it's not possible to use a variable in object notation initialization.

Other possible ways?

Alexander Beletsky
  • 18,875
  • 9
  • 60
  • 85

1 Answers1

3

You can use computed property names (which is an ES6 feature, but given you tagged your question as such I assume that's not a problem):

var update = {
  [name]   : data,
  resolved : true,
};
robertklep
  • 185,685
  • 31
  • 370
  • 359