javascript - defining field in z={ field : 'value'} using variable? -
var = 'this'; i want
var z = { a: 'that' } === { 'this': 'that'} where as:-
alert( z.this); // output 'undefined' alert(z.a); // output 'that' how define z's field using variable?
so that...
alert( z.this); // output becomes 'that' use case: dynamically create object z, instead of hardcoding fields.
in codee there no property this object z why alert(z.this) shows shows undefined. must not use property name reserved key word.
i think need define
var = 'this'; z[a]="that"; alert( z[a]); // output 'that'
Comments
Post a Comment