[thelist] string to multidimensional array

Peter Brunone (EasyListBox.com) peter at easylistbox.com
Mon Apr 2 10:03:24 CDT 2007


Hi Daniel,

    I've never had much success with multidimensional arrays in JS, but I have done some work (in VBScript and JScript) with what I like to call "multi-degree" arrays.

    Basically, each element in the array is also an array, and so on.  You'd have to loop through the initial array, but that's pretty simple.  Observe:

var arrParent = myString.split("],[");

for(var i=0;i<arrParent.length;i++) {
    arrParent[i] = arrParent[i].split(",");
    }

    Obviously this means you'd need to use different delimiters for the different levels, but since you can use multiple characters, that shouldn't be a problem.

HTH,

Peter

From: Daniel Kessler danielk at UMD.EDU

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.

thanks.

-- 

Daniel Kessler

College of Health and Human Performance
University of Maryland
Suite 2387 Valley Drive
College Park, MD 20742-2611
Phone: 301-405-2545
http://hhp.umd.edu



More information about the thelist mailing list