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

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

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

android - How to create dynamically Fragment pager adapter -