Tell me how to display all the values ​​in the array containing the word "analyst", in my example, only the values ​​for the first word are shown, it is necessary that all values ​​containing the word "analyst" are shown here http://jsfiddle.net/UKgD6/246/

var acList = ['smart analyst', 'analyst oversmart', 'smartland analyst', 'undersmart analyst', 'analyst verysmart', 'cool analyst smarter' ]; $('#ac').autocomplete({ source: function( request, response ) { var matches = $.map( acList, function(acItem) { if ( acItem.toUpperCase().indexOf(request.term.toUpperCase()) === 0 ) { return acItem; } }); response(matches); } 
 <input id="ac"> 

    2 answers 2

    To check whether a word is contained in a line at all, and not just at the beginning, replace the condition === 0 with != -1

     if ( acItem.toUpperCase().indexOf(request.term.toUpperCase()) != -1 ) 

    String.prototype.indexOf ()

    By the way, in this case autocomlete works and so

     var acList = ['smart analyst', 'analyst oversmart', 'smartland analyst', 'undersmart analyst', 'analyst verysmart', 'cool analyst smarter' ]; $('#ac').autocomplete({ source: acList }); 
    • Thank you for what you need)) - Fox
    • For the link to the adequate manual on index0f () and lastIndex0f () separate respect)) - Fox

    Try replacing $.map with $.grep .

    • nothing changed. - Fox