Why I have this error: Object doesn't support property or method 'forEach' for Internet Explorer?

和自甴很熟 提交于 2019-12-01 15:16:18

Yeap, its because IE8 does not implement Array.forEach (neither many other more modern JS methods). If you need to work in IE8, you will have to shim it (see the compatibility section).

By the way, MDN has resources for most of the other unsupported methods too.

Joe L.

This might help. To solve the problem in jQuery:

//This will fail in IE8
myObject.each(function(index, value){
 //your code goes here
});

//This will work in IE8 and all modern browsers
$.each(myObject, function(index, value){
 //your code goes here
});

You can also bind the unexisting forEach function to Array.prototype.forEeach.

(function () {
    if ( typeof NodeList.prototype.forEach === "function" ) return false;
    NodeList.prototype.forEach = Array.prototype.forEach;
})();

I found it in this post https://tips.tutorialhorizon.com/2017/01/06/object-doesnt-support-property-or-method-foreach/.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!