I have a kind of google suggest input box, it search in an array (list) for a word. I also have an object that the properties are those items in list.
When I input a word (sports in this case) I want searchStringInArray()
to write the object.property in another div. I have tried with definition.list[j]
, list[j]
being the match found in list.
var list = ["sports", "hockey"];
var definition = new Object();
definition.sports = "blablabla";
function searchStringInArray () {
$('#definition').empty();
var str=document.getElementById("text").value;
str = "\\b" + str + "\\b";
for (var j=0; j<list.length; j++) {
if(str.length > 4){
if (list[j].match(str)) {
alert(definition.list[j]);
document.getElementById("definition").innerHTML = definition.list[j];
}
}
}
}
I have tried many things with no success yet. if I change it to definition.sports, when I type sports in the input field it will work.