最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Using parameter names from variable in json object - Stack Overflow

programmeradmin2浏览0评论

Trying to work out a map reduce on mongo that would use field value as parameter name of the emitted object.

To simply what I'm tying to do is the following:

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

The object I wish to construct is:

{ "param1" : 12 }

Yet the being constructed is the following:

{ "param_name" : 12 }

Does JS support this "dynamic" behavior of object construction? (Mongo uses SeaMonkey JS engine, if that's relevant).

Thank you, Maxim.

Trying to work out a map reduce on mongo that would use field value as parameter name of the emitted object.

To simply what I'm tying to do is the following:

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

The object I wish to construct is:

{ "param1" : 12 }

Yet the being constructed is the following:

{ "param_name" : 12 }

Does JS support this "dynamic" behavior of object construction? (Mongo uses SeaMonkey JS engine, if that's relevant).

Thank you, Maxim.

Share Improve this question asked Apr 27, 2011 at 8:15 Maxim VekslerMaxim Veksler 30.2k40 gold badges134 silver badges153 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 10
emit_object[param_name] = param_value
emit_object[param_name]

The name is "bracket notation", there is also "dot notation to access" Object in javascript

发布评论

评论列表(0)

  1. 暂无评论