I currently am matching user input as follows:
user_input = "upload a file"
if ( "upload a file".indexOf(user_input.toLowerCase()) > -1 ) {}
This work fine but the problem is, it matches “a file” which I don’t want. I want it to only match if the beginning is correct.
This should match:
"upload"
"u"
"upload a"
This should not match, because the string does not match from the start:
"a"
"file"
Are there any suggestions on how to make this happen with indexOf?
indexOfreturn the index of the match, so if you want to test if it match at the beginning just check if it returns 0