Skip to content Skip to sidebar Skip to footer

Javascript Array Undefined In For Loop

I have a problem with a javascript array: 'arrFinal[i] is undefined' In my script arrFinal is dynamically generated function fillTextareas () { var arrFinal = []; arrFinal[0] = [];

Solution 1:

It looks like an off-by-one error in the outer loop.

It should be i < tailleArrFinal, not <=.

Solution 2:

By looking at your loop I can see at least 2 errors: you miss "var" and ".length" (you have to test for array length!)

try to replace:

for(i=0;i<=tailleArrFinal;i++){
        for(j=0;j<tailleArrSubFinal;j++) {
            $("form textarea#t" + i + "_" + j).val(arrFinal[i][j]);
        }
    }
}

with:

for(var i=0;i<tailleArrFinal.length;i++){
        for(var j=0; j<tailleArrSubFinal.length; j++) {
            $("form textarea#t" + i + "_" + j).val(arrFinal[i][j]);
        }
    }
}

Post a Comment for "Javascript Array Undefined In For Loop"