0

I have JSON structure like below:

const villages = 
{
"lossesOccured":
    [
        {
            "type": "destroyed",
            "affectedOn": "humans",
            "quantity": 120,
            "reliefFund": 100000,
            "location": {
                "district": "thanjavur",
                "villageName": "madukkur",
                "pincode": "614903"
            }
        },
        {
            "type": "physicalDamage",
            "affectedOn": "humans",
            "quantity": 250,
            "reliefFund": 50000,
            "location": {
                "district": "thanjavur",
                "villageName": "madukkur",
                "pincode": "614903"
            }
        },
    ]
}

I need help in displaying the JSON data in the form of table like below Using React. Also, need the table row to be added automatically whenever a new element is added in JSON. Output

1 Answer 1

1
<table>
  <thead>
    <tr>
      <th>AffectedOn</th>
      <th>Type</th>
      <th>Quantity</th>
    </tr>
  </thead>
  <tbody>
    {
      villages.lossesOccured.map(loss => (
        <tr>
          <td>{loss.affectedOn}</td>
          <td>{loss.type}</td>
          <td>{loss.quantity}</td>
        </tr>
      )
     }
  </tbody>
</table>
Sign up to request clarification or add additional context in comments.

1 Comment

Great. Thank you :)

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.