-
make several arrays from one array
Hello,
I need to be able to split my array into several arrays.
so far I have
PHP Code:
var Speech:Array = ["abcde", "abcde", "abcde", "abcde", "abcde", "abcde", "abcde", "abcde", "abcde", "abcde", "abcde"]; var Amount:Number = Speech.length;// 11 at present var Clipped:Number = 3;
the original array length does change, get longer over time, i always want the same divide.
clipped is the amount of arrays i want to split the array into( or any other number should i change it)
looking for this
PHP Code:
new array = (["abcde","abcde","abcde","abcde"],["abcde","abcde","abcde","abcde"],["abcde","abcde","abcde"])
I have absolutely no idea,
may thanks for looking
Last edited by Terrencing; 04-23-2013 at 09:22 AM.
-
.
Hi,
This is something I hacked together, perhaps it can be jiggled around a bit for better coding ???
try it and see what it traces for you.
PHP Code:
var A = ["abcde", "abcde", "abcde", "abcde", "abcde", "abcde", "abcde", "abcde", "abcde", "abcde", "abcde"];
var J:Number = A.length;
var NewArray:Array = [];
var MySplit:Number = 3;
var S:Number = 0;
var i:Number;
trace("// Original array started as [" + A + "]");
trace("// Original array length = " + J);
trace("// Split original array into arrays " + MySplit + " parts long,");
trace("// then create single end array with extra (if any).");
for (i = 0; i < J; i++)
{
NewArray[i] = [];
if (A.length < MySplit)
{
if (A.length < 1)
{
break;
}
else
{
CC = A.splice(0, A.length);
NewArray[i].push(CC);
trace("NewArray[[" + i + "]]=[" + NewArray[i] + "]" + " Array length = " + NewArray[i][0].length);
S++;
break;
}
}
else
{
CC = A.splice(0, MySplit);
NewArray[i].push(CC);
trace("NewArray[[" + i + "]]=[" + NewArray[i] + "]" + " Array length = " + NewArray[i][0].length);
S++;
}
}
trace("// " + S + " separate arrays have now been created from the original and merged.");
trace("// Original array finished as [" + A + "]");
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|