I already made the autocomplete work. The only problem is, the results is not optimized.
For example:
data: [Banana, Apple, Orange]
input: a
output in autocomplete: [Banana, Apple, Orange]
the output is arranged by their order in the array. It shows all the data because they all have the letter 'a' in them, which is correct but I need to show the first result that starts with letter 'a' (input).
Example:
my expected output: [Apple, Banana, Orange]
This is what I have done so far, unfortunately It is not showing any result. I am using Laravel Framework by the way. Thank you for your help.
source: function(request, response) {
var matcher = new RegExp("^" + $.ui.autocomplete.escapeRegex(request.term), "i");
response($.grep("data", function(item){
return matcher.test(item);
}) );
}