I've got an array thats being built from a CSV file, the array builds just fine:
0: Array[80]
0: "AM"
1: "AX"
2: "AR"
3: "JR"
4: "AC"
5: "AF"
etc...
I'm then trying to verify that a string taken from a text input appears at some point in the array. The variable for the value of the text input is created, but the indexOf()
always returns as -1
.
I originally thought that maybe the variable being compared (airlineCode
) was an object and that was the issue, but converting it to a string gives me the same results. After that I thought maybe I could just circumvent the indexOf()
by using jQuery.inArray()
, also got the same result. Code block looks like:
$("#employeeLoginButton").click(function(){
$.ajax({
url: "/template/AirlineBlock/airlineCodes.csv",
async: false,
success: function (csvd) {
data = $.csv2Array(csvd);
var airlineCode = document.getElementById('airlineCode').value;
airlineCode = String(airlineCode);
var found = data.indexOf(airlineCode);
console.log(airlineCode + found);
if(found != -1) {
sessionStorage.setItem("airlineVerified", true);
window.location.href = "http://somesite.com";
} else {
alert("Nope")
}
},
dataType: "text",
});
});