2

so basically i have this data:

const testMeasurments = [
  {
  data:[
  {name:"glucose",value:6,fill:'#57c0e8'},
  {name:"SpO2",value:5,fill:"#FF6565"},
  {name:"Blood Pressure",value:4,fill:"#FFDA83"},
  {name:"Body Weight",value:2,fill:"purple"}
  ]
}
]

what i want is to create an unordered list of values from this data. what i need is something like this:

<ul>
{testMeasurments.map(s=>
        <li>{s.data.value}</li>
)}
</ul>

to produce this:

        6
        5
        4
        2
1
  • And how have you tried to achieve this so far? Commented Jun 22, 2020 at 18:28

1 Answer 1

1

You need to iterate over both arrays to get to what you want to do.

<ul>
  { testMeasurments.map(
    s => s.data.map(
      m => <li>{m.value}</li>
    )
  )}
</ul>

See it live

Sometimes visualizing the data structure helps, I like to use Typescript to define the structure.

interface Measurement {
  data: MeasurementResult[]
}
interface MeasurementResult {
  name: string
  value: number
  fill: string
}

Here testMeasurments is of the same form as a Measurement[]. Meaning testMeasurments is an array of measurements. Each measurement has an array of "results". that is the inner array you are trying to get to :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.