0

I have an object called data. Within this object there is another object (or array, I'm not sure....), called maps. To reach maps I just do data.maps and this works on all browsers except for IE. When I console.log(data); i get this:

{
    "maps": [{
        "Media_Map_Id": "55",
        "Media_Id": "657"
    }]
}

When I console.log(data.maps); it says undefined....

I also got this error, it might have something to do with it eventhough I already fixed it.

Unable to get property 'length' of undefined or null reference

code:

    if(data.maps) {
        dMapsLength = data.maps.length;
    } else {
        dMapsLength = 0;
    }

    for (var i = 0; i < dMapsLength; i++) {
        createVars(data.maps[i], i);
    }

SOLVED (credits to evolutionxbox):

  if (typeof(data) !== 'object') {
       data = JSON.parse(data);
   }
Mike Lammers
  • 542
  • 9
  • 27

0 Answers0