我希望能够用用户输入的输入来搜索数组。因此,例如,如果用户在输入字段中输入“18”,根据数字18是否在数组中,“value not found”将出现或出现“value found”。使用用户输入搜索数组
这是我到目前为止。
var search = document.getElementById("search");
var arr = [18,23,20,17,21,18,22,19,18,20];
function beginhere() {
var input = document.getElementById("Input").value;
for (i=0; i<arr.length; i++){
if (arr[i] == Input) {
alert(arr[i]);
} else {
alert("Value not found");
}
}
};
JavaScript是大小写敏感的 – charlietfl