[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.
http://www.w3schools.com/jsref/jsref_split.asp
If you want a multidimensional array, you'll have to do something like
this:
- 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?
Jason
More information about the thelist
mailing list