javascript - Using function parameter value as dictionary key -



javascript - Using function parameter value as dictionary key -

attempting build dictionary using key comes via function parameter.

var progres_mark = function(progress_state) { var = date(); console.log({ progress_state : }) } progres_mark("encode")

expected

{ 'encode': 'sun oct 19 2014 18:22:33 gmt+0300 (idt)' }

actual

{ progress_state: 'sun oct 19 2014 18:22:33 gmt+0300 (idt)' }

what’s going on?

because compiler expects identifier or string , hence not evaluate variable's value. can utilize bracket notation accomplish want.

var progres_mark = function(progress_state) { var = date(); var obj = {}; obj[progress_state] = now; console.log(obj) }

javascript node.js dictionary

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -