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 = ['Beyond The Feilds','Blossoms Walk','Bluebells And Forget-Me-Knots','Breathe In And Believe','Colours Of The Land','Confetti Field','Dappled Earth','Elegance','Endless Light','Gulls Call','Hiding Hollyhocks','Lavender Fields','Lilypond Reflections','Meadow Hive','Meadow Home','nnnnn','Sea Mist','Secret Wild Garden','Surrounded By Birdsong 1','Top Of The Bay','Towards The Tide','Within Bluebell Wood' ]; var productsIDs = [ ]; $('#our-products .typeahead').typeahead({ hint: true, highlight: true, minLength: 1 }, { name: 'products', limit: 40, source: substringMatcher(products) });