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','Caerhays Sunset SOLD','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','Constantine Bay and Trevose Head','Foreshore Breaking Light. SOLD','Godrevy Lighthouse','Gyllyngvase Shoreline','Hemmick Reflections','Hemmick Beach (study)SOLD','Light on the Ocean','Luxulyan Stream','Meeting at the Surf','Mor an Myghtern ( Sea King : Cornish )','Mordon Ruvanes ( Queen of Waves : Cornish )','Painting','Polruan to Gribben Head','Portmellon Valley View','Rock Pools and Breakers','Rockpool Reflections','Sennen Beach Storm Breakers','Sennen Cove North Rocks II. SOLD','Summer Oak Meadow. SOLD','Surfer','Swanpool Winter Sun. SOLD','Tideline Reflections','Toward the Ocean SOLD','Towards Gull Rock from Hemmick SOLD','Twilight Flora SOLD','Walkers on Towan Beach','Whitesand Waves' ]; $('#our-products .typeahead').typeahead({ hint: true, highlight: true, minLength: 1 }, { name: 'products', limit: 10, source: substringMatcher(products) });