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 = ['10 Square Metre Project Pack','11" (50 x 75 x 280mm) Cast Dress Stone Coping','12" Decorative Flat Top','12" Flat Top with 45° Chamfer','12" Standard 4 Weathered','12" Standard Quad Cap','15" (50 x 75 x 380mm) Cast Dress Stone Coping','15" Decorative Flat Top','15" Flat Top with 45° Chamfer','15" Standard 4 Weathered','15" Standard Quad Cap','18" 4 Weathered Decorative Base','18" Decorative Base 4 Weathered with 9" Sphere','18" Decorative Base with Flat Top','18" Decorative Flat Top','18" Flat Top with 45° Chamfer','18" High Peak with High Base','18" High Peak with High Quad Edge','18" High Peak with Panels','18" Standard 4 Weathered','18" Standard Quad Cap','21" 4 Weathered Decorative Base','21" Decorative Base 4 Weathered with 9" Sphere','21" Decorative Base with Flat Top','21" Decorative Flat Top','21" Flat Top with 45° Chamfer','21" High Peak with High Base','21" High Peak with High Quad Edge','21" High Peak with Panels','21" Standard 4 Weathered','21" Standard Quad Cap','5½" (50 x 75 x 140 mm) Cast Dress Stone Coping','7" (50 x 75 x 180 mm) Cast Dress Stone Coping','9" (50 x 75 x 225mm) Cast Dress Stone Coping','9" Decorative Flat Top','9" Flat Top Liner with 45° Chamfer','9" Standard 4 Weathered','9" Standard Quad Cap','Balustrading end column / pier set','Balustrading set','Bevel Edged Quoin Block','Chamfered 140mm Keystone','Chamfered 215mm Keystone','Complete Pillar Set with 18" Decorative Flat Top','Complete Pillar Set with 21" Decorative Flat Top','Coping Stones 11"','Coping Stones 15"','Coping Stones 5.5"','Coping Stones 7"','Coping Stones 9"','Door Surround','Full 9" Set with 18" Decorative Base','Full 9" Set with 18" Quad Base','Full 9" Set with 21" Decorative Base','Full 9" Set with 21" Quad Base','Gable Vent 590mm X 330mm X 120mm','Head/Lintel - 215','Head/Lintel 140','Large Neck Stand for Sphere','Large Sphere - 12" Diameter','Pillar Cap 12"','Pillar Caps 15"','Pillar Caps 18"','Pillar Caps 21"','Pillar Caps 24"','Pillar Caps 9"','Quoin Cladding','Slimline Keystone for 140mm Head','Slimline Keystone for 215mm Head','Slip Cill 175','Slip Cills 150','Small Neck Stand for Sphere','Small Sphere - 9" Diameter','Standard Chamfered Head','Standard Reconstituted Splayed Head.','Stooled Cill 150','Stooled cill 175','Window Cill 9" x 3" @ 1050mm','Window Cill 9" x 3" @ 1500mm','Window Cill 9" x 3" @ 1800mm','Window Cill 9" x 3" @ 1200mm','Window Cill 9" x 3" @ 1350mm','Window Cill 9" x 3" @ 1650mm','Window Cill 9" x 3" @ 1950mm','Window Cill 9" x 3" @ 2100mm','Window Cill 9" x 3" @ 2250mm','Window Cill 9" x 3" @ 2400mm','Window Cill 9" x 3" @ 900mm','Window Cill 9"x3" @750mm' ]; $('#our-products .typeahead').typeahead({ hint: true, highlight: true, minLength: 1 }, { name: 'products', limit: 20, source: substringMatcher(products) });