[thelist] string to multidimensional array

Jason Handby jason.handby at corestar.co.uk
Mon Apr 2 09:59:31 CDT 2007

Hi Daniel,

> I have a string, '[[1,"myName"],[2,"myOtherName"]]'.  I feed this to  
> js as a variable.  How do I turn this into a multidimensional 
> array.   
> So far, I can only create an array of length==1.
> Do I have to parse through it?  So far I've been avoiding that.

You can use the split() function to do what you want.


If you want a multidimensional array, you'll have to do something like

 - remove the outer []
 - call split(), specifying "," as the separator, to split into an array
of strings
 - index through the items in the array, taking each string, removing
its [], splitting it on "," and putting the result back into the array
in place of the string you just split

See what I mean?


More information about the thelist mailing list