var myarr= Array(‘test1′,’test2′,’test3’);
var searchTerm = "test";
var rSearchTerm = new RegExp( searchTerm,'i');
$.each(myarr, function(i) {
if (myarr[i].match(rSearchTerm)) {
//item found
}
});
guys is there any way to make my search algorithm better ? “myarr” will be a big array so i want to make sure that i’m using the best way to search in it
thanks alot
I would recommend the following (since jQuery provides this convenience):
The only other approach to make this faster is probably to do this without jQuery in a plain
for-loop, since it does not involve callbacks:EDIT: I changed
.match()to.test(), like Andy E suggested.