Easy question: I'm trying to add a number to an array like this:
sorted[4][2]+=nbrMvt[i];
but it adds the two numbers as if they were strings. The output just puts the numbers one beside the other... I have tried these methods:
sorted[4][2]+=parseInt(nbrMvt[i]);
sorted[4][2]=sorted[4][2]+nbrMvt[i];
sorted[4][2]=parseInt(sorted[4][2])+parseInt(nbrMvt[i]);
But none of them work.
[EDIT]
Ok, here is how I created my array:
var sorted = MultiDimensionalArray(13,4);
I then atribute string values to the sorted[x][0...12]
the last example gives me "NaNNaNNaNNaN"
function MultiDimensionalArray(iRows,iCols)
{
var i;
var j;
var a = new Array(iRows);
for (i=0; i < iRows; i++)
{
a[i] = new Array(iCols);
for (j=0; j < iCols; j++)
{
a[i][j] = "";
}
}
return(a);
}
(btw, what should I understand from the vote down on my question?)
sortedvariable. More than likely it's values are strings, causing the+=to be concatenation.MultiDimensionalArray(13,4). Are you using a framework?