Can I use a Regular Expression within jQuery.inArray()

后端 未结 5 677
刺人心
刺人心 2021-01-07 06:42

I would like the following if statement to alert \'yes\' if \'featured\' is in array, regardless of whether it is uppercase or lowercase.

I\'m also not

5条回答
  •  长发绾君心
    2021-01-07 07:16

    No, I don't think so.

    This is how I would to it, using ($.each and match()):

    var myArray = ["featured", "foo", "bar"];
    
    
    $.each(myArray,function(index,value){
        if(value.match(/featured/i) !== null){
            alert("Yes!");
            return false;
        }
    });
    

    on JSFIDDLE: http://jsfiddle.net/QGtZU/

提交回复
热议问题