Javascript 在IE8中forEach不工作,如何将此代码更改为工作
我在JS中有这段代码,但在IE8中不起作用Javascript 在IE8中forEach不工作,如何将此代码更改为工作,javascript,each,Javascript,Each,我在JS中有这段代码,但在IE8中不起作用 Offices.forEach(function(trade) { console.log('Id for this trade is: '+trade.ID); }); 如何使其工作?foreach在IE8中不受支持(请参阅)。这是垫片: if (!Array.prototype.forEach) { Array.prototype.forEach = function(fun /*, this
Offices.forEach(function(trade) {
console.log('Id for this trade is: '+trade.ID);
});
如何使其工作?
foreach
在IE8中不受支持(请参阅)。这是垫片:
if (!Array.prototype.forEach)
{
Array.prototype.forEach = function(fun /*, thisArg */)
{
"use strict";
if (this === void 0 || this === null)
throw new TypeError();
var t = Object(this);
var len = t.length >>> 0;
if (typeof fun !== "function")
throw new TypeError();
var thisArg = arguments.length >= 2 ? arguments[1] : void 0;
for (var i = 0; i < len; i++)
{
if (i in t)
fun.call(thisArg, t[i], i, t);
}
};
}
if(!Array.prototype.forEach)
{
Array.prototype.forEach=函数(fun/*,thisArg*/)
{
“严格使用”;
if(this==void 0 | | this==null)
抛出新的TypeError();
var t=对象(本);
var len=t.length>>>0;
如果(乐趣的类型!=“功能”)
抛出新的TypeError();
var thisArg=arguments.length>=2?参数[1]:无效0;
对于(变量i=0;i
或者你可以使用一个像这样的库,它有自己的跨浏览器实现。请显示一些努力,至少是google.console.log,ie8不支持它。如果你不打开开发工具,请查看此帖子