'How to access the data inside this object in react?
Solution 1:[1]
i think this post will help you:
https://stackoverflow.com/questions/71936347/reactjs-how-can-i-access-data-from-nested-object-fetched-api/71936484#71936484
you can use map like a previos post then go through all the elements.
you can do like:
{Object?.map(o=>(
<div key={o.id}>
<h1>{o.name}</h1>
<h1>{o.address}</h1>
</div>
))}
Solution 2:[2]
Since the 'data' is an object, you can try this:
data['0'].name
If you want to get 'name' of all values in an array, you can try this:
Object.values(data).map(v => v.name)
Solution 3:[3]
This article might help. https://www.digitalocean.com/community/tutorials/4-uses-of-javascripts-arraymap-you-should-know
Basically, you need to iterate/map through the items in the object.
Array.map((item) => {}))
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Hiba Youssef |
| Solution 2 | Tabrez Basha |
| Solution 3 |
