This is a continuation of a question I asked yesterday, where I asked how to determine if the input matches any portion of an array's element ('sun' & 'sunday' = 'sun'). Here was the solution.
var _array = ["sun", "mon", "tue", "wed", "thu", "fri", "sat"];
for (var i = 0; i < _array.length; i++) {
if (_val.indexOf(_array[i]) != -1) {
$('span').text('it worked');
return;
}
}
$('span').text('nothing');
I just realized however that, if true, I need to match it with the full name value in an associative array. Ex: if you type ('sun','sund','sunda', or 'sunday') it returns 'sunday'. Ideally it would be case insensitive, but I can figure that out on my own.
var _array = {
"sun" : "sunday",
"mon" : "monday",
"tue" : "tuesday",
"wed" : "wednesday",
"thu" : "thursday",
"fri" : "friday",
"sat" : "saturday"
};
Here is the second part of the solution. I realize I could just remove the else {
$('p').text('');
} in this example but that won't work in my project code.