1 Replies - 2248 Views - Last Post: 29 April 2012 - 05:44 AM

#1 hadi_php  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 10
  • View blog
  • Posts: 382
  • Joined: 23-August 08

Need help on jquery array match

Posted 29 April 2012 - 04:35 AM

var array = [ "Foo", "Food", "Good", "Test", "God" ];

arr = $.map(array, function (value) {
                      search = /oo/gi;
                      if(value.match(search)) return value;
                      return null;
                    }
                 );


arr return a array matched on main array. Problem is here - search = /oo/gi;

"oo" is a string. I am trying pass a variable instead of oo

Like -

var src_keyword = 'oo';
var array = [ "Foo", "Food", "Good", "Test", "God" ];

arr = $.map(array, function (value) {
                      search = /src_keyword/gi; // here i am trying to pass variable but its not passing...
                      if(value.match(search)) return value;
                      return null;
                    }
                 );


Is This A Good Question/Topic? 0
  • +

Replies To: Need help on jquery array match

#2 hadi_php  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 10
  • View blog
  • Posts: 382
  • Joined: 23-August 08

Re: Need help on jquery array match

Posted 29 April 2012 - 05:44 AM

Already found the solution :)

by using -
var search = new RegExp(src_keyword, "gi");

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1