How to match a pattern against an array in JavaScript?

we have $.inArray(searchString, array) function in jQuery, but this will look for the exact match of the string in the values present in the array. But how to check the string in the array like indexOf?

For e.g., Let us take the string "mark_zuck" and if the array looks like this, ["mark", "sheryl", "zuck"]. We can do this by using a loop comparing each value in array with the given string like,

for (i=0; i<array.length; i++) {
    searchString.indexOf(array[i]);
}

I'm looking for a better way to implement this. Please help.

Answers


array.filter(function(a){
  return searchString.indexOf(a) !== -1;
}

Need Your Help

Heroku: how to detect if foreman is running

django heroku foreman

I am using eclipse to develop my Django project, and it will be deployed to Heroku. In order to detect if the app is running on Heroku, the settings.py is modified:

PIC16F887 Timer0 counting overflows

assembly pic microchip

I'm using the PIC16F887 44-pin Demo board.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.