- Home /
Question by
Waka-Takaki · May 25, 2014 at 10:47 PM ·
javascriptarraymultidimensional arraymultidimensional
Multidimensional array variable size (JS)
The syntax I'm using with my array is this:
var multiArray : String[,];
and usually I'd instantiate like so:
multiArray = new String[4,4]; //or something similar
but I need to populate my array with an unknown amount of values, as they will be coming from a Split()
string of variable length.
I know the length of the first dimension of the array but not the second.
multiArray = new String(knownArray.length, variableLength);
I'm only able to get the length of the second dimensions after I've already assigned the first dimension of the multi-dimensional array. eg.:
for(var i=0; i<knownArray.length; i++)
{
var sArray : String[] = knownArray[i].Split(","[0]);
for(var x=0; x<sArray.length; x++)
{
multiArray[i,x] = sArray[x];
}
}
How would you suggest I acheive this functionality?
Comment
Answer by Jeff-Kesselman · May 25, 2014 at 10:49 PM
For arrays of dynamic size in Unity use new Array().
for two dimensions, one of which is known, you can declare a fixed size array of Arrays.
http://wiki.unity3d.com/index.php?title=Head_First_into_Unity_with_UnityScript