Reputation: 103
I have an array of objects, which in turn can contain arrays. How can I iterate over the inner array within a map? If I try like this, I'll get one
TypeError: postData.to_json.map is not a function
return (
<div className="App">
{daten.length > 0 &&
daten.map((postData) => (
<>
<h3 key={postData.id}>ID: {postData.id}</h3>
{postData.to_json.map((data) => (
<>
<h3 key={data}>INFO: {data}</h3>
</>
))}
</>
))}
</div>
);
My data looks like this
Upvotes: 1
Views: 232
Reputation: 19049
You need to convert to_json
(which is typeof string, not an array) to an array object by:
{ JSON.parse(postData.to_json).map((data) => ( ... ) }
Upvotes: 1