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
Post a Comment