I have some code which seems to work just fine:
async function myfunction(ref) {
var r1 = await getReport(ref, "queue", "hour", "2018-10-03", "2018-10-04", "pageviews", "page");
var r2 = await getReport(r1.reportID, "get").then(r2 => reportHandler(r1.reportID, r2, 0));
console.log(r2);
}
The console.log(r2); outputs this result:
{report: {…}, waitSeconds: 0, runSeconds: 0}
report:
data: Array(4)
0:
breakdown: [{…}]
breakdownTotal: ["608674"]
day: 1
month: 10
name: "Mon. 1 Oct. 2018"
year: 2018
__proto__: Object
1:
breakdown: [{…}]
breakdownTotal: ["564566"]
day: 2
month: 10
name: "Tue. 2 Oct. 2018"
year: 2018
I'm trying to output the value of 'breakdownTotal' using code I have built using online tutorials
const result = data.report.data.reduce((r, e) => {
e.breakdownTotal.forEach(el => {
let key = "data";
if(!r[key]) r[key] = []
r[key].push(...el.counts)
})
return r;
}, {})
However, I get this error:
Uncaught (in promise) ReferenceError: data is not defined
at myfunction (mytest3.html:12)
breakdownTotalas output right?r2.breakdownTotalisn't working?datahere? how and where do you call this function?dataso it's obviously undefined. There is no magicdatavariable