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
Post a Comment