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 = ['Atlantic Light','Bedruthan Steps','Camel Estuary View','Card "Whitesand Cove"','Card"Atlantic Foreshore"','Card"Atlantic Surf"','Card"Beach Walker"','Card"Cape Cornwall Dusk"','Card"Godrevy"','Card"Into the Surf"','Card"Nanjizal"','Card"River Inlet"','Card"Riverflow"','Card"Sea, Snow and Teasels"','Card"Spring Flora"','Card"Stream to Ocean"','Card"Valley Dusk"','Card"Walkers at Whitesands"','CardTwilight Thistles"','Clifftop Twilight','Coast Path to Maenporth','Coastal Colours','Constantine Bay and Trevose Head SOLD','Cornish Coastal Foxgloves','Cornish Mackerel','Cornish Twilight Hedgerow','Edible Crab','Fowey Estuary Light','Godrevy Lighthouse','Gyllyngvase to Swanpool, Falmouth','Hidden Gate','John Dory','Last Light Over Atlantic Tide','Lerryn Bridge','Light on the Ocean','Looking out from Hemmick, The Roseland','Luxulyan Valley Stream','Mor an Myghtern ( Sea King : Cornish )','Mordon Ruvanes ( Queen of Waves : Cornish )','painting','Pentire from Polzeath','Polruan to Gribben Head','Polzeath to Pentire Point','Returning Home, Porthleven','Sailing into Fowey and distant Grbbin Head','Sailing Past The Blockhouse, Polruan','Secluded Bridge, Tregargus','Signs of Spring','Spring Tide Walkers','St. Anthony from Gylly','Stream to Surf','Summer Light Over Distant Gribbin Head','Sunset Walkers','Surf King','Surf Queen','Surfer','Swanpool Summer','Through The Gateway','Tideline Reflections','Towan Beach, The Roseland','Toward the Surf','Twilight Surfers, Watergate Bay','Watching the Sunset','Whitesand Waves','Wild Flowers and High Tide, Towan Beach' ]; $('#our-products .typeahead').typeahead({ hint: true, highlight: true, minLength: 1 }, { name: 'products', limit: 10, source: substringMatcher(products) });