JavaScript: forEach method not supported in Internet Explorer

I am using a javascript implementation of the gzip algorithm that works fine with Firefox and Chrome. But with Internet Explorer, I got the following error:

The forEach method is not supported!

Code:

deflate.deflate(data, level).forEach(function (byte) { putByte(byte, out); }); 

I am using Internet Explorer 9, which must support the forEach method.

Any ideas?

Thank you very much!

+6
source share
2 answers

You can try and extend the Array object for browsers that do not support the foreach method on it, as suggested here by Array.forEach

One example:

 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); } } } 
+17
source

forEach is not supported in IE9, you can try using jquery.
ex:

 $. each (function (byte) { putByte(byte, out); }); 
0
source

Source: https://habr.com/ru/post/946085/


All Articles