[Chartjs]-Array .map() returning undefined

1👍

Your array is two-dimensional and map is iterating only the first dimension, i.e:

-[]
  -0: Array(31)     // first dimension
    -0:             // second dimension
      -date: "2018-08-26T00:00:00-04:00"
      ...

This would look like the following JSON string:

[[{"date":"2018-08-26T00:00:00-04:00", ...}]]

Since you haven’t provided a full example it’s impossible to recommend the most applicable solution:

  • If you control the data source, remove the first dimension since it appears redundant.
  • Assuming you only want the first element of the first dimension, refer to that key:

    this.data[0].map((value) => value.date);
    

If your data model is more complex than revealed in your question you’ll need to figure out another approach.

Leave a comment