Javascript ForEach函数在IE中不起作用

我怎么能写下以下所有浏览器都支持的代码? 因为似乎IE8中不支持forEach-Function …

digits.forEach( function( value, index ) { // create a span with initial conditions var span = $( '', { 'class': 'digit0', 'data': { 'current': 0, 'goal' : value } } ); // append span to the div#number span.appendTo( $( 'div#number' ) ); // call countUp after interval multiplied by the index of this span setTimeout( function() { countUp.call( span ); }, index * interval ); } ); 

请在此处查看完整的代码 : http : //jsfiddle.net/bBadM/ (它不适用于所有浏览器)提前致谢。

问候,

forEach的MDN文档包括在实现早期版本的JS的浏览器中使用的方法的两种实现。

我将在这里重现快速的(请参阅完整的链接):

 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);    }  } }