Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript: Method forEach not supported from Internet Explorer

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!

like image 263
Alexander Schreiber Avatar asked May 29 '13 12:05

Alexander Schreiber


1 Answers

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);
        }
    }
}
like image 162
Subedi Kishor Avatar answered Nov 05 '22 23:11

Subedi Kishor