I am trying to map a dynamically created Object to an Array like this
params.junctionBarriers = dojo.toJson(junctionBarriers);
// printing the object in the console (Please look at attached image)
console.log(params.junctionBarriers);
var value = [];
var data = params.junctionBarriers.map(function (s) {
value.push(webMercatorUtils.xyToLngLat(s.x, s.y, true));
return s;
})
but I am getting this error
params.junctionBarriers.map is not a function
As you can see from the image the params.junctionBarriers
is dynamically loaded but the .map()
is not valid. Why is this, and how I can fix it?
Look at the documentation for dojo.toJson
That method converts an object to a string in JSON format.
A String does not have the method map.
So why don't you simply do junctionBarriers.map
? given you already have the array of objects in that variable (which is NOT params.junctionBarriers)