How do I dynamically name an element in an object in javascript? -


i creating object in function:

createobject(attr) {     return {         attr: "test"     } } 

i want attr named function parameter. right end object:

{     attr: "test" } 

how do this?

create new object , use bracket notation set property.

function createobject(attr) {     var obj = {};     obj[attr] = "test";     return obj; } 

Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -