I ran into the same problem with objects, not with a simple string array, and sorting should be done after retrieving the results (to achieve the βstartswithβ sentences at the top of the list). therefore, for future search engines I will add my solution.
using jQuery, you can search for lines in your result object label that begin with user input and combine the rest of the result with them, after merging, use the Underscore.js library to remove duplicates.
eg:
var objects_array = [{"label":"A_ABC","value":"0"},{"label":"B_ABC","value":"1"},{"label":"C_ABC","value":"2"}]; $(document).ready ( function() { $('#search').autocomplete({ source: function (request, response) { var results = $.ui.autocomplete.filter(objects_array, request.term); var top_suggestions = $.grep(results, function (n,i) { return (n.label.substr(0, request.term.length).toLowerCase() == request.term.toLowerCase()); }); var merged_results = $.merge(top_suggestions,results); var final_results = _.uniq(merged_results,"label"); response(final_results); } }); });

Example result: http://i.stack.imgur.com/GKJ8d.png
Stavm source share