Why doesn't indexOf work on an array IE8?

后端 未结 7 923
耶瑟儿~
耶瑟儿~ 2020-11-22 04:15

The below function works fine on Opera, Firefox and Chrome. However, in IE8 it fails on the if ( allowed.indexOf(ext[1]) == -1) part.

Does anyone know w

7条回答
  •  感动是毒
    2020-11-22 04:59

    If you're using jQuery and want to keep using indexOf without worrying about compatibility issues, you can do this :

    if (!Array.prototype.indexOf) {
        Array.prototype.indexOf = function(val) {
            return jQuery.inArray(val, this);
        };
    }
    

    This is helpful when you want to keep using indexOf but provide a fallback when it's not available.

提交回复
热议问题