I have this code in JS, which doesn't work in IE8.
Offices.forEach(function(trade) {
console.log('Id for this trade is: '+trade.ID);
});
How can I make it work?
I have this code in JS, which doesn't work in IE8.
Offices.forEach(function(trade) {
console.log('Id for this trade is: '+trade.ID);
});
How can I make it work?
foreach
is not supported in IE8 (see documentation). Here's the shim:
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);
}
};
}
Or you could use a library like underscore which has its own cross-browser implementation.