thepeskykid
04-29-2003, 06:17 PM
Hello,
I have been struggling with this for a couple of hours now and I can't see the wood for the trees...
function process_debts()
{
if (mainArray.length == 0)
{
alert("You must have entered at least one debt");
return;
}
var tempArray1 = new Array(2);
var tempArray2 = new Array(0);
for (i=0; i<mainArray.length; i++)
{
tempArray1[0] = mainArray[i][0];
tempArray1[1] = mainArray[i][4];
tempArray2[i] = tempArray1;
}
}
the above is supposed to iterate through the 2 dimensional array mainArray (which contains numerous arrays, each containing 7 items), copying items 0 and 4, placing these copies into 'slots' 0 and 1 of the temporary array tempArray1, then adding this 2 item array to the end of another array (tempArray2)
E.G.
if mainArray = ( (1,2,3,4,5,6,7) , (2,3,4,5,6,7,8) )
#1 iteration, tempArray1 = (1,4)
#2 iteration, tempArray1 = (2,5)
resulting in...
tempArray2 = ( (1,4) , (2,5) )
but I get...
tempArray2 = ( (2,5) , (2,5) )
Can anyone point out what I am doing wrong?
Thank you
I have been struggling with this for a couple of hours now and I can't see the wood for the trees...
function process_debts()
{
if (mainArray.length == 0)
{
alert("You must have entered at least one debt");
return;
}
var tempArray1 = new Array(2);
var tempArray2 = new Array(0);
for (i=0; i<mainArray.length; i++)
{
tempArray1[0] = mainArray[i][0];
tempArray1[1] = mainArray[i][4];
tempArray2[i] = tempArray1;
}
}
the above is supposed to iterate through the 2 dimensional array mainArray (which contains numerous arrays, each containing 7 items), copying items 0 and 4, placing these copies into 'slots' 0 and 1 of the temporary array tempArray1, then adding this 2 item array to the end of another array (tempArray2)
E.G.
if mainArray = ( (1,2,3,4,5,6,7) , (2,3,4,5,6,7,8) )
#1 iteration, tempArray1 = (1,4)
#2 iteration, tempArray1 = (2,5)
resulting in...
tempArray2 = ( (1,4) , (2,5) )
but I get...
tempArray2 = ( (2,5) , (2,5) )
Can anyone point out what I am doing wrong?
Thank you