0

I have problem when call the nested in react js using map. I use https://jsonplaceholder.typicode.com/users. The json like this:

[
  {
    "id": 1,
    "name": "Leanne Graham",
    "username": "Bret",
    "email": "[email protected]",
    "address": {
      "street": "Kulas Light",
      "suite": "Apt. 556",
      "city": "Gwenborough",
      "zipcode": "92998-3874",
      "geo": {
        "lat": "-37.3159",
        "lng": "81.1496"
      }
    },
    "phone": "1-770-736-8031 x56442",
    "website": "hildegard.org",
    "company": {
      "name": "Romaguera-Crona",
      "catchPhrase": "Multi-layered client-server neural-net",
      "bs": "harness real-time e-markets"
    }
  },
]

i wan to call street in address, but not work.

here is my code on react js :

       {items.map((item, id)=>
          <div className="">
            <h3>{item.name}</h3>
            <p>{item.phone}</p>
              {item.address.map((show)=>(
                <p>{show.street}</p>
              ))}
          </div>
       )}

1 Answer 1

1

Array.map() is a function to be used for arrays, but item.address.street here is just a string. Instead of using

{item.address.map((show)=>(
  <p>{show.street}</p>
))}

to access the property of the object, use

{item.address.street}
Sign up to request clarification or add additional context in comments.

1 Comment

Happy to help. Since this worked for you, please mark the answer as accepted

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.