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 = ['Barware','Bins','Bread-making','Cake and Muffin Tins','China','Coffee','Cooks knives','Cups & Saucers and Mugs','Cutlery','Flat tins and biscuits','Food preparation','Gifts for your table and home','Glassware','Jamie Olivers Paella Recipe','Linen','Paella','Pasta','Pots and Pans','Salt and pepper mills','Specialist tins','Storage','Table-top cooking','Tea','Trays, Trivets, Coasters & Placemats','Washing & Ironing','Washing-up and Cleaning','Woks and World Flavours','Woodware' ]; $('#our-products .typeahead').typeahead({ hint: true, highlight: true, minLength: 1 }, { name: 'products', limit: 20, source: substringMatcher(products) });