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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -