JavaScript:Internet Explorer 不支持 Method forEach
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16813469/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JavaScript: Method forEach not supported from Internet Explorer
提问by Alexander Schreiber
I'm using a javascript implementation of the gzip algorithm which works fine with Firefox and Chrome. But with Internet Explorer I got the following error:
我正在使用 gzip 算法的 javascript 实现,它适用于 Firefox 和 Chrome。但是使用 Internet Explorer 时出现以下错误:
Method forEach is not supported!
不支持 forEach 方法!
Code:
代码:
deflate.deflate(data, level).forEach(function (byte) {
putByte(byte, out);
});
I'm using Internet Explorer 9, which should support the forEach Method.
我正在使用 Internet Explorer 9,它应该支持 forEach 方法。
Any ideas?
有任何想法吗?
Thank you very much!
非常感谢你!
回答by Subedi Kishor
You might try and extend the Array
object for browsers that don't support the foreach
method on it as suggested here Array.forEach
您可以尝试Array
为不支持其foreach
上的方法的浏览器扩展对象,如建议hereArray.forEach
One example is:
一个例子是:
if (!Array.prototype.forEach) {
Array.prototype.forEach = function(fn, scope) {
for(var i = 0, len = this.length; i < len; ++i) {
fn.call(scope, this[i], i, this);
}
}
}
回答by Vignesh Paramasivam
forEach is not supported in IE9, you can try using jquery.
ex:
IE9 中不支持 forEach,您可以尝试使用 jquery。
前任:
$. each (function (byte) {
putByte(byte, out);
});