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

mysql - FireDac error 314 - but DLLs are in program directory -

c++ - Getting C2512 "no default constructor" for `ClassA` error on the first parentheses of constructor for `ClassB`? -

java - How can I send the data from a imput type="file" to the controller? -