Why can't I access my JS Object Properties?

113 Views Asked by At

I'm trying to reformat JSON Data from a REST Api in order to display the data with d3. The d3 code is within an angular component, but I think the problem is more related to javascript. The template I want to use is here: https://bl.ocks.org/mbostock/3884955

The data I get is formated as array of objects (of which I just want to print the first one) formated like that:

{"time":["2018-09-17T12:44:16.985Z","2018-09-17T12:44:17.982Z"],
    "counts":[
            [3539.8,3539.4],
            Arr(2),
            Arr(2),
            Arr(2),
            Arr(2)
    ]
}

--> five measuring points with two (in this example) measurements each

this is how the d3-code expects the data:

(local var) data: {
id: string;
values: {
    date: any;
    count: any;
}[];

the code I tried to achieve that:

   var keys_all=d3.keys(data[0].counts);
   var measurementData = keys_all.map(function(id) {
   return {
    id: id.toString(),
    values: data[0].counts[id].map(function(d,i) {
      return {date: data[0].time[i], count: d};
    })
   };
   });  

When I console.log(), the result is exactly what I expected. But I cannot access the properties "date" and "time" in my following code.

When I hover over the result variable, VS Code only shows:

(local var) data: {
id: string;
values: any;
}[]

I also tried to log the stringified Object and this works as well.

Any ideas what could go wrong?

0

There are 0 best solutions below