I'm trying to create a cache for retrieving XML data.
My problem is im getting an error "TypeError: Cannot find function forEach in object"
I dont understand why im getting the error and i copied most of this out from an example.
The error occurs at:
priceIDs.forEach (function (row) {
row.forEach ( function (cell) {
if (typeof(cell) === 'number' ) {
dirtyTypeIDs.push(cell);
}
});
});
The line "row.forEach ( function (cell) {" appears to be the culprit. I will post the whole of the code below for people to help :)
function LoadPrices(priceIDs, systemID,cacheBuster){
if (typeof systemID == "undefined") {
systemID=30000142;
}
if (typeof priceIDs == "undefined") {
throw "need typeids";
}
if (typeof cacheBuster == "undefined") {
cacheBuster=1;
}
var prices = new Array();
var dirtyTypeIDs = new Array();
var cleanTypeIDs = new Array();
var url = "http://api.eve-central.com/api/marketstat?cacheBuster="+cacheBuster+"&usesystem="+systemID+"&typeid=";
priceIDs.forEach (function (row) {
row.forEach ( function (cell) {
if (typeof(cell) === 'number' ) {
dirtyTypeIDs.push(cell);
}
});
});
cleanTypeIDs = dirtyTypeIDs.filter(function(v,i,a) {
return a.indexOf(v)===i;
});
var parameters = {method : "get",payload: ""};
var xmlFeed = UrlFetchApp.fetch(url+cleanTypeIDs.join("&typeid="),parameters).getContent();
var xml = XmlService.parse(xmlFeed);
if(xml)
{
var rows=xml.getRootElement().getChild("marketstat").getChildren("type");
for(var i = 0; i< rows.length; i++) {
var price = [rows[i].getAttribute("id").getValue(),
rows[i].getChild("sell").getChild("volume").getValue(),
rows[i].getChild("sell").getChild("avg").getValue(),
rows[i].getChild("sell").getChild("max").getValue(),
rows[i].getChild("sell").getChild("min").getValue(),
rows[i].getChild("sell").getChild("stddev").getValue(),
rows[i].getChild("sell").getChild("median").getValue(),
rows[i].getChild("sell").getChild("percentile").getValue(),
rows[i].getChild("buy").getChild("min").getValue(),
rows[i].getChild("buy").getChild("avg").getValue(),
rows[i].getChild("buy").getChild("max").getValue(),
rows[i].getChild("buy").getChild("min").getValue(),
rows[i].getChild("buy").getChild("stddev").getValue(),
rows[i].getChild("buy").getChild("median").getValue(),
rows[i].getChild("buy").getChild("percentile").getValue(),
];
prices.push(price);
}
};
}
Can any help me understand the error and correct it?
rowis an array,forEach()is an Array method.priceIDs?