Checking to see if value is in datalist or not
Your code is a bit hard to read, but I suggest that

array.indexOf(element)


or 

array.some(callback)


is what you are looking for.

Documentation:

indexOf

some