9

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:

Method forEach is not supported!

Code:

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

I'm using Internet Explorer 9, which should support the forEach Method.

Any ideas?

Thank you very much!

My Stack Overfloweth
  • 4,729
  • 4
  • 25
  • 42
  • 1
    forEach isn't supported in IE8. IE9 should support it, however. http://kangax.github.io/es5-compat-table/#Array.prototype.forEach – James Donnelly May 29 '13 at 12:09
  • 2
    Is your page running in quirks mode in IE? (Perhaps by accident?) `.forEach()` is only supported in standards mode. Does `deflate.deflate()` always return an array? – nnnnnn May 29 '13 at 12:15
  • Rather than extending a built-in object, you can replace the `forEach` part with a 2 line `for` loop. – RobG May 29 '13 at 12:23

2 Answers2

23

You might try and extend the Array object for browsers that don't support the foreach method on it as suggested here Array.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);
        }
    }
}
Subedi Kishor
  • 5,906
  • 5
  • 35
  • 53
0

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

$. each (function (byte) {
  putByte(byte, out);
});
Vignesh Paramasivam
  • 2,360
  • 5
  • 26
  • 57