javascript - How to get this object as the result -


in javascript declared var = "p", b = "q", c = "r";

and var obj = {a : "x", b: "y", c:"z"};

and want var obj = { "p": "x" , "q": "y", "r": "z"}

but not getting same.

you can either use computed property this:

var obj = {[a]: "x", [b]: "y", [c]: "z"} 

or can use obj[a] other's have suggested means use value in a name of key.

note: computed properties won't have support in every environment. see "browser compatibility" section in link posted above.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -