Creating a javascript object with dynamic property name

Firat Tiryaki

You should use eval function for that.

Check out the below lines, sure it will help;

x=new Object();
propertyName="nameProperty";
propertyValue="John";
eval("x."+propertyName+"='"+propertyValue+"'");
alert(x.nameProperty);

0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact