Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create Dynamic Object

Status
Not open for further replies.

solepixel

Programmer
May 30, 2007
111
US
I'm trying to create an object similar to the one in this thread:
I am extracting a string from an HTML element that looks like this: {option1: 'var', option2: false, option3: 'stuff'}

I tried var options = myString, but then I cannot reference options['option1']. How do I do that?

I tried var options = new Object(); but that still didn't help. Thanks.
 
You'd need to eval the string to turn it into an object (one of the few good uses for eval):

Code:
var myString = "{option1: 'var', option2: false, option3: 'stuff'}";
var options = eval(myString);
alert(options.option1);

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top