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 = ['1 - HDB Woollen Twisting Frame 130 Spindles 160mm ring Year 1995','1 - HDB 3000mm Galaxy Woollen Card Year 2005, 160 good ends (Ref. 12169)','1 off Fibre Flow Technologies Step Cleaner (Ref. 12130)','2 - HDB Woollen Spinning Frames Year 2002 160 spindles (Ref. 12169)','2 off Savio Two for One TDS 15N Twisting Year 1995','ANDAR 2 x Burner Uni Dryer 300kgs/hr Year 2000','CA6 Worsted Card Double Doffer 2500mm Year 1994 (13065)','Cliffe Tow Cutter (Ref. 12174)','Dornier P2 Year 2022 for Carbon Fibre or Glass Fibre Weaving','Fabotex WF1 Fringing Machine Year 2015','Gilbos MCGF Winding Machine Year 1997 (Ref. 13070)','Haigh Chadwick Fearnought 1800mm (Ref. 12169A)','Haigh Sample Card 300mm / 12 inch (Ref:13055)','Haigh-Chadwick Hopper Feeder (Ref.12157)','HDB Double Doffer Nonwoven Card 2500mm (Ref. 13058)','KARL MAYER ROB Warping Machine Year 2003 (Ref. 16082)','Lafer Fringeing Model FRV 2000 Year 1987','Laroche Starcut cutting machine (ref.12165)','NSC Scglumberger FM8 Horizontal Rubbing Frame Year 1997 14082D','NSC Schlumberger FM8N Horizontal rubbing frame 20 spindles Year 1996 (Ref. 14082B)','PAOLI Rotary Cutter 2004 (Ref. 12164)','Staubli Unival 512 Electronic Jacquard Year 2010 (16081)','Tatham BLOW FILLING PRODUCTION LINE FOR PILLOW / CUSHIONS','Tatham Laboratory Non Woven Carding and Needle Loom line (13067)','Tatham Laboratory( Research/Sample) Non Woven Card','Tatham Small Non Woven Carding Needle line ( 130167)','Thibeau CA6 Non Woven Card Double Doffer 2500mm Year 1994 (13065)' ]; var productsIDs = [ ]; $('#our-products .typeahead').typeahead({ hint: true, highlight: true, minLength: 1 }, { name: 'products', limit: 40, source: substringMatcher(products) });