How to fix Array indexOf() in JavaScript for Internet Explorer browsers

前端 未结 10 1480
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-22 03:09

If you have worked with JavaScript at any length you are aware that Internet Explorer does not implement the ECMAScript function for Array.prototype.indexOf() [includin

10条回答
  •  旧时难觅i
    2020-11-22 03:43

    You should check if it's not defined using if (!Array.prototype.indexOf).

    Also, your implementation of indexOf is not correct. You must use === instead of == in your if (this[i] == obj) statement, otherwise [4,"5"].indexOf(5) would be 1 according to your implementation, which is incorrect.

    I recommend you use the implementation on MDC.

提交回复
热议问题