0

Display JSON data in the table

I am having an issue to access my JSON data. It is inside the array of objects of objects. How can I do that?

I am using the map function to display it, but only the name and avatar. It is nested.

JSON data

[ { "id": "1", "person": { "name": "Prerna Jha", "avatar": "profile.jpg" }, "city": "Mumbai", "email": "[email protected]", "joiningDate": "12/02/2018", "role": "UI Designer" }, ] {data.map((curElem) => { const { id, name, avatar, city, email, joiningDate, role } = curElem; return ( <tbody key={id}> <tr> <td>{name}</td> <td>{avatar}</td> <td>{city}</td> <td>{email}</td> <td>{joiningDate}</td> <td>{role}</td> </tr> </tbody> ); })} 

I have got few data and nested objects, but I am not getting it.

1

1 Answer 1

1

You need to access the person object first in the main JSON data:

const { id, person, city, email, joiningDate, role } = curElem; const {name, avatar} = person 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.