我试图将输入的文本与来自预定义数组的单词列表进行匹配。但是,它不会返回任何内容,即使console.log也不会返回任何内容。我无法弄清楚为什么out循环没有启动。任何帮助将不胜感激。我的嵌套循环无法正常工作
var actions = ["north", "south", "east", "west", "up", "down", "get", "take", "pick up", "use", "drop", "open", "close"];
var inputTextBox = document.getElementById("inputTextBox");
inputTextBox.addEventListener("keypress", function(event) {
var stringArray = [];
var x = event.which || event.keyCode;
var inString = inputTextBox.value.toLowerCase();
if (x === 13) {
stringArray = inString.split(" ");
console.log("stringArray is --- " + stringArray + " --- length is " + stringArray.length);
for (var i = 0; i < stringArray; i++) {
console.log("outer loop is " + stringArray[i]);
for (var j = 0; j < actions.length; j++) {
if (stringArray[i] === actions[j]) {
console.log(stringArray[i]);
}
}
}
}
}
<input id="inputTextBox" type="text" maxlength="200" placeholder="words here" autofocus></input>