我目前使用jquery 1.8.3。我认为它将 indexOf
添加到 Array.prototype
中,所以现在我的每个数组始终包含方法 indexOf 作为第一个元素。
执行 for (var i in object)
我总是将方法 infexOf 作为我的第一个元素,它会干扰我的代码。
该错误仅发生在 IE8 上。
我想要的是从所有数组中删除这个indexOf,或者无论如何破解jquery/解决这个问题。
PS:我什至不确定是否是 jquery 导致了这个问题
谢谢。
最佳答案
除了不使用 for...in
迭代数组之外,如果必须使用 for...in
,请将其与 hasOwnProperty 结合使用
判断您正在查看的属性是否确实属于相关对象,或者来自原型(prototype):
for (var prop in myObject) {
if (myObject.hasOwnProperty(prop)) {
// this didn't come from the prototype.
}
}
关于javascript - IE8 数组和indexOf冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16695492/