Search code examples
javascriptarraysjsonautocompletearray-push

Javascript - Array push for AutoComplete


I am working on a AutoComplete search bar that reads from an array. I am needing to parse a JSON file and push the names into an array. I have everything working except for the right command to push to the actual array. What would I use to push to the array below?

    $("#schoolLocal").autocompleteArray(
    [],
    {
        delay:10,
        minChars:1,
        matchSubset:1,
        onItemSelect:selectItem,
        onFindValue:findValue,
        autoFill:true,
        maxItemsToShow:10
    }
);

I used $("#schoolLocal").autocompleteArray.push(name);

And of course that didn't work.

Any help is appreciated. Thank you!


Solution

  • what is autoCompleteArray? an array or a function?

    Assuming it's an array then:

    // declare the array  with 2 sub arrays,1 for names and other for definitions (?)
    $("#schoolLocal").autocompleteArray = new Array(new Array(),{
            delay:10,
            minChars:1,
            matchSubset:1,
            onItemSelect:selectItem,
            onFindValue:findValue,
            autoFill:true,
            maxItemsToShow:10
        }
    );
    
    //push to the names array
    $("#schoolLocal").autocompleteArray[0].push(name);