var substringMatcher = function(strs) { return function findMatches(q, cb) { var matches, substringRegex; // an array that will be populated with substring matches matches = []; // regex used to determine if a string contains the substring `q` substrRegex = new RegExp(q, 'i'); // iterate through the pool of strings and for any string that // contains the substring `q`, add it to the `matches` array $.each(strs, function(i, str) { if (substrRegex.test(str)) { matches.push(str); } }); cb(matches); }; }; var products = ['網,掏','網,掏 網,掏','Beetle','Product Name 10','Product Name 11','Product Name 14','Product Name 15','Product Name 17','Product Name 18','Product Name 2','Product Name 20','Product Name 21','Product Name 22','Product Name 25','Product Name 26','Product Name 27','Product Name 28','Product Name 29','Product Name 3','Product Name 30','Product Name 33','Product Name 34','Product Name 35','Product Name 36','Product Name 37','Product Name 38','Product Name 39','Product Name 40','Product Name 41','Product Name 42','Product Name 44','Product Name 45','Product Name 47','Product Name 48','Product Name 49','Product Name 5','Product Name 50','Product Name 51','Product Name 52','Product Name 53','Product Name 54','Product Name 57','Product Name 58','Product Name 59','Product Name 6','Product Name 60','Product Name 61','Product Name 62','Product Name 63','Product Name 64','Product Name 65','Product Name 66','Product Name 67','Product Name 68','Product Name 69','Product Name 7','Product Name 70','Product Name 8','Product Name 9' ]; $('#our-products .typeahead').typeahead({ hint: true, highlight: true, minLength: 1 }, { name: 'products', limit: 20, source: substringMatcher(products) });