The actual question is this (Stack Overflow limits characters in the questions):
How do i check if a string is present from a textbox in a (non-static) multidimensional array and then display the first item in the array from which the string was found in? (using jQuery)
For example:
(this is not what I'm actually doing, this is just for an example. I understand the example I'm providing has a much simpler solution. That's not what I'm after, though)
HTML
<input type="text" id="textbox">
<div id="output"></div>
JS:
var array = [
["that's an ice-cream topping","sprinkles","chocolate syrup"],
["that's a pizza topping","basil","cheese"],
["that's a car part","wheel","headlights","windshield wipers"]
];
('#textbox').keyup(function(){
if(/*a match is found from the textbox in the array*/){
('#output').html(/*first item in the array the string was found in*/);
} else {
('#output').html();
}
});
This is what I'm trying to achieve: If a user types "sprinkles and stuff" in the textbox, as soon as "sprinkles" is typed, the output would display "that's an ice-cream topping."
Side-note: This assumes that typing "That's an ice-cream topping" into the textbox would also display "That's an ice-cream topping." This also assumes that the arrays could be changed and are never the same.