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 -

wpf - C# NAudio - Changing audio playback position still plays a small buffer of old position -

Log not being recorded for quickfix c++ Session -