By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,528 Members | 1,338 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,528 IT Pros & Developers. It's quick & easy.

How to add a property to an object at runtime

P: n/a
Is there a way to add a property to a javascript object at runtime if
you don't the name until runtime?

For Example:

var oTestObj = new Object();
//In the real world the value of sPropertyName would be calculated.
var sPropertyName = "NewProperty";

//How do you add a property whos name is the value of sPropertyName?

oTestObj.NewProperty = "Somevalue";

Sep 9 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
oTestObj[sProperty]="Somevalue";

Sep 9 '05 #2

P: n/a

Correct, obj[WHATEVER IS THE STDOUT/output EXPANDED HERE].someprophere;

Danny
Sep 10 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.