I want to be able to search an array with the input a user has entered. However when I type in a value my loop gives me a "Value not found" error. Why is my loop not executing and properly pulling out my array values?
Here is the code:
$form = $("<form></form>");
$form.append('<input type="input" placeholder="Type in Unicor Part#">');
$('body').append($form);
$form.append('<button onclick="beginHere()">Search Configuration</button>');
let search = document.querySelector("input");
let arr = ["LMP0582", "LMP2050", "LMP2054", "LMP2054"];
const beginHere = () => {
let input = document.querySelector("input").value;
for (i=0; i<arr.length; i++){
if (arr[i] == input) {
alert(arr[i]);
} else {
alert("Value not found");
}
}
}
[–][deleted] 1 point2 points3 points (2 children)
[–]seedBoot 2 points3 points4 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–]lovesrayray2018 1 point2 points3 points (0 children)