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