Any way to make jQuery.inArray() case insensitive?

后端 未结 8 1638
轮回少年
轮回少年 2020-12-03 16:44

Title sums it up.

8条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-03 17:07

    You can use each()...

    // Iterate over an array of strings, select the first elements that 
    // equalsIgnoreCase the 'matchString' value
    var matchString = "MATCHME".toLowerCase();
    var rslt = null;
    $.each(['foo', 'bar', 'matchme'], function(index, value) { 
      if (rslt == null && value.toLowerCase() === matchString) {
        rslt = index;
        return false;
      }
    });
    

提交回复
热议问题