0

Im looping an associative array and testing entries name with a regexp.test(), and some entries, that should, do not match with it, but if I use StringObj.match(regexp) this works.

And the more strange thing is that test() works if I use execute match earlier...

var pattern = new RegExp(".*" + this.value + ".*", "gmi");

     //console.log(pattern);
     for (var key in data) {

        //console.log(data[key].name.match(pattern));

        if ( pattern.test(data[key].name) )
        {
           console.log(data[key].name + " - " + key);
           $("#d-"+key).show();
        }
        else
        {
           $("#d-"+key).hide();
        }

     }

"this.value" is an input value that I fetch on keyup.

If console.log(match()) is commented test() does not wotk properly, if I uncomment it the works.

( I do not want an alternative to do this, I know how do it, I would like an explanation for this, I think, weird behavior).

Thank you in advance.

Markus Laire
  • 2,837
  • 2
  • 17
  • 23
xpeiro
  • 733
  • 5
  • 21

0 Answers0