我收到错误,我不明白为什么。错误是说“无法读取未定义的属性'长度”。
我的代码是:
outLetters = PC.substring(0,1);
var outLetters2 = PC.substring(1, 2);
outNumbers = Number(PC.substring(2,3));
currentPosition = outLetters;
console.log(secondLetters[currentPosition].length); //this returns 8
for(fl = 0; fl < firstLetter.length; fl++) {
if(firstLetter[fl] === currentPosition) {
console.log(secondLetters[currentPosition].length); //this returns 8
for(number = 0; number < secondLetters[currentPosition].length; number++) { //this is where the error is showing
if(secondLetters[currentPosition][number] === outLetters2) {
currentPosition = PC.substring(0, 2);
for(num = 0; num < outCodes[currentPosition.toUpperCase()].length; num++) {
if(outCodes[currentPosition.toUpperCase()][num] === outNumbers) {
valid = true;
break;
}
}
}
}
break;
} else {
valid = false;
}
}
我评论过两行,因为在我看来,长度属性正常工作,直到我把它放在我的for循环中。
提前感谢您的帮助。