# How do I push 0[i] into an array

I cant figure out how to push a series of zeroes into an array.
What I want is to populate the array with zeroes if the array is empty, which it will be the first time of the iteration.

``````for(i = 0; i < colorList.length; i++){
var statList:Array=[];
if(statList.length>=1){
statList=new Array();
statList=statArray;
}
else{
statList=new Array(i);
statList[i]=0;
}
}
But my trace only results in this
//,,,,,,,,,0
there is 10 items in colorList
``````
###### Who is Participating?

Commented:

``````var colorList:Array = new Array(10);
var statList:Array;

for(var i:uint = 0; i < colorList.length; i++){
if(!(colorList[i] is Array)){
colorList[i] = new Array();
}
statList = colorList[i];
statList.push(0);
}

//Test if we can append a new value
for(i = 0; i < colorList.length; i++){
statList = colorList[i];
statList.push(1);
}

//Print all values
for(i = 0; i < colorList.length; i++){
trace("Index: " + i + ", values: " + colorList[i]);
}
``````
0

Commented:
Are you trying yo create a double array metrix?

I don't see you are pushing statList into colorList.

0

Author Commented:
Im trying to use the length from colorList to create a status for each of a series of movies.
like this.
``````statArray=statList
myMovie.status = statArray[i];
``````
eventually statArray will be changed from a lot of zeroes to fx. 0,0,0,1,0,0,1,1,0,0

0

Commented:
or

``````var colorList:Array = new Array(10);

for(var i:uint = 0; i < colorList.length; i++){
if(!(colorList[i] is Array)){
colorList[i] = new Array();
}
var statList:Array = colorList[i];
statList.push(value);
}
}

//Test if we can append a new value

//Print all values
for(var i:uint = 0; i < colorList.length; i++){
trace("Index: " + i + ", values: " + colorList[i]);
}
``````
0

Author Commented:
I think you are on the right track, but the trace for the last example results in this:
Index: 0, values: 0,0,0,1,1,0,0
Index: 1, values: 0,0,0,1,1,0,0
Index: 2, values: 0,0,0,1,1,0,0
Index: 3, values: 0,0,0,1,1,0,0
Index: 4, values: 0,0,0,1,1,0,0
Index: 5, values: 0,0,0,1,1,0,0
Index: 6, values: 0,0,0,1,1,0,0
Index: 7, values: 0,0,0,1,1,0,0
Index: 8, values: 0,0,0,1,1,0,0
Index: 9, values: 0,0,0,1,1,0,0

If I for the last part replace colorList with statList it results in this
``````for(var i:uint = 0; i < colorList.length; i++){
trace("Index: " + i + ", values: " + statList[i]);
}
``````
Index: 0, values: 0
Index: 1, values: 0
Index: 2, values: 0
Index: 3, values: 1
Index: 4, values: 1
Index: 5, values: 0
Index: 6, values: 0
Index: 7, values: undefined
Index: 8, values: undefined
Index: 9, values: undefined

0

Author Commented:
This has solved the problem, so if its alright with you, Ill close the question

``````statList=[];
if(statArray.length>=1){
statList=new Array();
statList=statArray;
}
else{
statList=new Array();
for each(var p:Number in colorList){
statList.push(0);
}
}
``````
0

Commented:
Thank you for feedback but I didn't get points from you :(
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.