1

I've got a chart component here with simple data, dates and temperatures.What i wanted the table function to do is to log out the results array Only (ideally with just the Date key) on the console.

The table function is passed onto the OnCLick on the chart component so when a bar is clicked, an object is logged onto the console. I just need to narrow down the results array and log out just the Date bit

my function is on line 52 : https://codesandbox.io/s/floral-violet-822vg?file=/src/chart.js

this is what is currently being logged onto the console when a bar is clicked:

enter image description here

I just the results array to be logged onto the console. Thank you in advance

Shuib Abdillahi
  • 119
  • 1
  • 10
  • 1
    You currently do `console.log(data.datum.dimensions);` but you can go further... `data.datum.dimensions[0].datum.data.result`? – DemiPixel Apr 08 '21 at 22:32
  • Thank u! and how would I get the Date key and value from it ? i tried data.datum.dimensions[0].datum.data.result.Date but no luck. Would I need to use the map method or? – Shuib Abdillahi Apr 09 '21 at 06:24
  • @ShuibAbdillahi yes you could use map. `console.log(data.datum.dimensions[0].datum.data.result[0].Date);` gives a single date back. If you loop/map over `data.datum.dimensions[0].datum.data.result` you can get the `Date` property of every element in the `result` array. See this [pastebin](https://pastebin.com/DF9EPZrM) for an example of a map function for `result`. – 5eb Apr 09 '21 at 06:47
  • Thank u! I know its simple but just wanted to be sure so I can get back to it after work – Shuib Abdillahi Apr 09 '21 at 14:55

0 Answers0