-1

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?

Alex
  • 8,908
  • 28
  • 103
  • 157
  • Show some effort please, at least google. – u_mulder Apr 03 '14 at 11:27
  • console.log, its not supported in ie8 if you dont open dev tools , check this post http://stackoverflow.com/questions/690251/what-happened-to-console-log-in-ie8 – Xavi Apr 03 '14 at 11:28

1 Answers1

0

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.

net.uk.sweet
  • 12,444
  • 2
  • 24
  • 42