I'm working on a fairly simple web application that accepts user input in either number or word form. The basic premise behind this is I need to find the word in the array if I start with the number and/or the index number of the word if I start with the word. I have created a function that can do both. The only catch is, if I don't manually type out the list like let generic_list = ["Item1", "Item2", "Item3"];
, the index isn't found when trying to load it from the text file.
The code I am using to load the text file is:
$.get("list.txt", function(data) {
let list_loaded = data.split("\n");
})
This is the code that I'm using to find the index that works if I manually make the list.
let item_index = list_loaded.indexOf(item_index_im_searching_for);
When I manually create the list, the return value will be the proper index number. If the text file loads the list the value will return -1 undefined. I've done some reading around, but I'm not exactly sure what I'm missing. Hoping some of you JavaScript vets can lead me to the right direction.
Also, when testing in the console, both lists appear to exactly the same.