0

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.

Kris Harper
  • 5,672
  • 8
  • 51
  • 96
Mobidoy
  • 353
  • 1
  • 3
  • 11
  • See also exact same problem at http://stackoverflow.com/q/11230063/1048572, and https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Operators/Member_Operators#Bracket_notation for solution – Bergi Apr 29 '13 at 20:12
  • @PSCoder: No, he wants `definition[ list[j] ]` – Bergi Apr 29 '13 at 20:13

0 Answers0