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
  • 19,453
  • 9
  • 63
  • 86

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
  • 198,204
  • 35
  • 394
  • 381