jquery - Search regular expression in JavaScript -
the search regular expression in array jquery autocomplete not working correctly.
i have array:
var names = [ "jorn zaefferer", "scott gonzalez", "john resig" ];
here autocomplete function of jquery:
$( "#developer" ).autocomplete({ source: function( request, response ) { var matcher = new regexp('^'+request.term,'g'); var arr=new array(); for(var i=0;i<names.length;i++) { var index=0; if(matcher.test(names[i])===true) //not returning true { console.log("it true"); arr.push(names[i]); } else { console.log("not done"); } } response(arr); } });
the conditional statement:
if(matcher.test(names[i])===true)
in code not returning true. why?
you need remove g
flag on regular expression can leave regular expression object state 1 search next , can mess things up. there should no reason in particular use of regex.
then, further help, need show searching in array never returning true.
when start getting matches, if you're trying accumulate matches, need move initialization of arr
variable before for
loop isn't reinitialized in every iteration of for
loop.
Comments
Post a Comment