Error: Loop Variable Undefined

Error: Loop Variable Undefined

我正在尝试遍历一个数组,但它无法看到预期的输出。相反,当我尝试调试时,它说变量 r 未定义。这是用于 for loop 的变量。

调试界面

上下文中的代码

function checkClassType(idOfEl,dropElem)
{
    var ElementType="";
    if (dropElem == "stream ui-draggable") {

        for(var r=0;r<100;r++)
        {
            if(createdImportStreamArray[r][0]==idOfEl)
            {
                ElementType="importStream";
                finalArray[idOfEl-1][2]= createdImportStreamArray[r][1]; //Selected Stream from Predefined Streams
                finalArray[idOfEl-1][3]= createdImportStreamArray[r][2]; //asName

            }
            else if(createdExportStreamArray[r][0]==idOfEl)
            {
                ElementType="exportStream";
                finalArray[idOfEl-1][2]= createdExportStreamArray[r][1]; //Selected Stream from Predefined Streams
                finalArray[idOfEl-1][3]= createdExportStreamArray[r][2]; //asName
            }
            else 
            {
                ElementType="definedStream";
                finalArray[idOfEl-1][2]= createdDefinedStreamArray[r][1]; //Stream Name
                finalArray[idOfEl-1][3]= createdExportStreamArray[r][4]; //Number of Attributes
                finalArray[idOfEl-1][4]=[];
                for(var f=0;f<createdExportStreamArray[r][4];f++)
                {
                    finalArray[idOfEl-1][4][f][0]=createdDefinedStreamArray[r][2][f][0]; //Attribute Name
                    finalArray[idOfEl-1][4][f][1]=createdDefinedStreamArray[r][2][f][1]; // Attribute Type
                }
            }
        }
    }

    else if (dropElem == "wstream ui-draggable") {
             //Continues...

但是,根据我的假设,r 将继续获取 0 到 99 之间的值。那么它怎么可能是 undefined

尝试在方法的开头声明 r 变量

function checkClassType(idOfEl,dropElem)
{
var r=0
var ElementType="";
if (dropElem == "stream ui-draggable") {

    for(;r<100;r++)
    {
        if(createdImportStreamArray[r][0]==idOfEl)
        {
            ElementType="importStream";
            finalArray[idOfEl-1][2]= createdImportStreamArray[r][1]; //Selected Stream from Predefined Streams
            finalArray[idOfEl-1][3]= createdImportStreamArray[r][2]; //asName

        }
        else if(createdExportStreamArray[r][0]==idOfEl)
        {
            ElementType="exportStream";
            finalArray[idOfEl-1][2]= createdExportStreamArray[r][1]; //Selected Stream from Predefined Streams
            finalArray[idOfEl-1][3]= createdExportStreamArray[r][2]; //asName
        }
        else 
        {
            ElementType="definedStream";
            finalArray[idOfEl-1][2]= createdDefinedStreamArray[r][1]; //Stream Name
            finalArray[idOfEl-1][3]= createdExportStreamArray[r][4]; //Number of Attributes
            finalArray[idOfEl-1][4]=[];
            for(var f=0;f<createdExportStreamArray[r][4];f++)
            {
                finalArray[idOfEl-1][4][f][0]=createdDefinedStreamArray[r][2][f][0]; //Attribute Name
                finalArray[idOfEl-1][4][f][1]=createdDefinedStreamArray[r][2][f][1]; // Attribute Type
            }
        }
    }
}

else if (dropElem == "wstream ui-draggable") {
         //Continues...