1

Been struggling with this for some time now and would appreciate any insight you guys have..

This is what my JSON Data looks like..enter image description here

BinsByDayByOrchardsQCs [Array] > BinsByDayByOrchardsQCsDefects [Array]

I need to display each "Defect" on a grid table, which is inside the array of BinsByDayByOrchardsQCsDefects which will look something like this enter image description here

What I have so far is {this.state.rows.map((qc) => <div className="row table">{qc.BinsByDayByOrchardsQCs[0].BinsByDayByOrchardsQCsDefects[0].Defect}</div>

This currently returns Hail Damage, Sunburn, Sunburn, Sunburn, my question to you guys is how do I return all the defects from the whole array not just [0]

1
  • 1
    Can you make an StackBlitz or Codepen example to check the code? On the other hand, if you want to iterate not only on 0 you can do `this.state.rows.map((qc, index) => allothercode). Cheers, sigfried. Commented Apr 19, 2019 at 21:23

1 Answer 1

3

I like using Lodash for collection manipulation.

But you could also use nested maps:

{
    this.state.rows.map((qc) =>
        qc.BinsByDayByOrchardsQCs.map((qc2) =>
            qc2.BinsByDayByOrchardsQCsDefects.map((qc3) =>
                <div className="row table">
                    {qc3.Defect}
                </div>
            )
        )
    )
}
Sign up to request clarification or add additional context in comments.

1 Comment

Sorry for the late reply my man, but this is working perfectly...Cheers!

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.