# How to combine Vector3 arrays?

Here is an example in JS:

``````var vArray:Vector3[];
var positions:Vector3[];

}

``````

How would I combine two arrays like this? A single array out of two arrays.

Any hint is very much appreciated.

You can use System.Array.Copy:

``````function CombineVector3Arrays (array1 : Vector3[], array2 : Vector3[]) : Vector3[] {
var array3 = new Vector3[array1.length + array2.length];
System.Array.Copy (array1, array3, array1.length);
System.Array.Copy (array2, 0, array3, array1.length, array2.length);
return array3;
}

``````

Arrays can't be resized so you have to create a new array that is big enough to hold the elements of both arrays.

``````var vArray:Vector3[];
var positions:Vector3[];

var tmpArray = new Vector3[vArray.length + positions.length];
var i = 0;
for (var V : Vector3  in vArray) {
tmpArray[i++] = V;
}
for (var V : Vector3 in positions) {
tmpArray[i++] = V;
}
vArray = tmpArray;
}

``````

But with a List it would be simpler

``````var vArray:Vector3[];
var positions:Vector3[];

var tmpArray = new List.<Vector3>(vArray);
vArray = tmpArray.ToArray();
}

``````

I'm not at my home computer so can't check whether this exactly right, but it should give you an idea...

``````var i:int;

for (i=0; i<vArray.Count; i++)
{
vArray _+= positions*;*_
_*}*_
_*```*_
_*<p>If += doesn't work then change the line to:</p>*_
_*```*_
<em><em>vArray <em>= vArray _+ positions*;*_</em></em></em>
<em><em><em>_*```*_</em></em></em>``````