schorle88
schorle88

Reputation: 103

Map in a map function over another array

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

enter image description here

Upvotes: 1

Views: 232

Answers (2)

Josie
Josie

Reputation: 175

change postData.to_json.map to JSON.parse(posData.to_json).map

Upvotes: 0

Samuli Hakoniemi
Samuli Hakoniemi

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

Related Questions