我正在尝试使用 .indexOf 来查明数组是否包含字符串。某事导致错误,但我不知道是什么。我确信这是一件真正简单的事情,但我不懂这种语言,所以看不到它。怎么了?
//this code creates an error in IE
var myMines=new Array();
var newMine="22";
var myVar = myMines.indexOf(newMine); //when I comment out this line, the page does not generate an error
最佳答案
您是否偶然使用 IE 8(或更低版本)? Array.indexOf
仅适用于 IE 9+、Firefox 3+ 和 Chrome 7+。
来源:http://kangax.github.com/es5-compat-table/
Array.indexOf
的文档(还包括在不支持它的浏览器中实现它的函数):https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf
关于javascript - 为什么我的 indexOf 语句会产生错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10016492/