javascript - how can i define a object with Variables? -
this question has answer here:
i want add object variables, this
a = 'name' object = {'age': 12, 'weight': 120} i want
{'name': 'bob'}   i
object = {a: 'bob'}  but give me
{'a': 'bob'} how can fixed it? must use variables
just assign bracket notation after deleting former content.
var = 'name',      object = { 'age': 12, 'weight': 120 };    object = {};       // delete properties  object[a]= 'bob';  // assign new property  document.write('<pre>' + json.stringify(object, 0, 4) + '</pre>');
Comments
Post a Comment