Using parameter names from a variable in json object

An attempt to work out a map is reduced by mongo, which will use the field value as the parameter name of the emitted object.

Just what I need to do is the following:

emit_object = {} param_name = "param1" param_value = 1 emit_object.param_name = param_value 

The object I want to build:

 { "param1" : 12 } 

Nevertheless, the constructed construction is as follows:

 { "param_name" : 12 } 

Does JS support this "dynamic" behavior of the object construct? (Mongo uses the SeaMonkey JS engine, if relevant).

Thank you, Maxim.

+4
source share
2 answers
 emit_object[param_name] = param_value 
+10
source
 emit_object[param_name] 

The name is a "symbol", there is also a "notation point for access" Object in javascript

+3
source

All Articles