I need to add recurrently a 2 dimensional array. The ideea is that I have a generated 2 dimensional array and I have to get the sum of all the generated arrays. I tried writing:
sum+=parseFloat(twoArray[a][b]);
however the script is blocked and I do not get anything. it is a loop so the values of a, b float from 0 to a variable inserted by the user. I have tested the script and this is the line where it breaks.
if (k>=3){
for(var i=0;i<A.length;i++){
var smaller=new Array(A.length-1);
for(var h=0;h<smaller.length;h++){
smaller[h]=new Array(smaller.length);
}
for(var a=1;a<A.length;a++){
for(var b=0;b<A.length;b++){
if(b<i){
smaller[a-1][b]=A[a][b];
}
else if(b>i){
smaller[a-1][b-1]=A[a][b];
}
}
}
sum+=parseFloat(smaller[a][b]);
alert (sum);
//dam valorile
}
}
}
smallerhas no item at[a][b], as it's length is onlya-1. Could you please post the error you get when "the script breaks"?