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 = ['A.R.T. Wild Meadow Grasses. Cotswold Sculpture Park','bbb','Blossom Trees. Earlier Adult Art Class. WED 12TH AUGUST. 3.00pm-5.30pm. Brookthorpe Village Hall. Stroud Road. GL4 0URL','Blossom Trees. Later Adult Art Class. WED 12TH AUGUST. 6.30pm-9.00pm Brookthorpe Village Hall. Stroud Road, GL4 0UR','Blossoms Walk','Bluebells And Forget-Me-Knots','Breathe In And Believe','Colours Of The Land','Confetti Field','Daisy Dip','Dandelion Clocks.','Dappled Earth','Dreams Seeded In Winter 1','Dreams Seeded In Winter 2','Elegance','Endless Light','Field Of Wishes.','Golden Hour','Gulls Call','HARBOUR WINDOW. Earlier Adult Art Class. WED 26TH AUGUST. 3.00pm-5.30pm. Brookthorpe Village Hall. Stroud Road. GL4 0URL','HARBOUR WINDOW. Later Adult Art Class. WED 26TH AUGUST. 6.30pm-9.00pm Brookthorpe Village Hall. Stroud Road, GL4 0UR','Hiding Hollyhocks','Hiding Hollyhocks.','IN BLOOM! ADULT SATURDAY WORKSHOP. SATURDAY 19th September 10.00am -5.30pm. Brookthorpe Village Hall. Stroud Road, GL4 0UR','kk','Lavender Fields','Loves Me, Loves Me Not.','Meadow Hive','Meadow Blue','Meadow Home','mmmm','Murmer In The Meadows','nnnnn','painting','Sea Mist','Secret Wild Garden','Small Works Placeholder - more items arriving soon','ssss','THE PAINTING TABLE. Saturday 23rd August 10.30am - 1pm. The Costwold Sculpture Park. GL7 6FE. (Not suitable for children under 15yrs)','Through The Grasses','Top Of The Bay','Towards The Tide','Waiting For Butterflies','Wild Daisy Meadow','Wild Flower Path','Wild Grasses','Within Bluebell Wood','xxx','zzzzz' ]; var productsIDs = [ ]; $('#our-products .typeahead').typeahead({ hint: true, highlight: true, minLength: 1 }, { name: 'products', limit: 40, source: substringMatcher(products) });