0

I am trying to extract JSON data from an api, but running into issues. When I console.log the data, it shows...

enter image description here

I am trying to access name from the returned json object.I tried to log json.(whatever) from the object and is shows undefined.

const fetchData = async () => {
           const response = await fetch('http://swapi.dev/api/vehicles/30/')
           const json = response.json();
           console.log(json);
        }
    
fetchData();

1 Answer 1

2

You need to await response.json as well.

So it should look like this

const fetchData = async () => {
       const response = await fetch('http://swapi.dev/api/vehicles/30/')
       const json = await response.json();
       console.log(json);
    }

fetchData();
Sign up to request clarification or add additional context in comments.

Comments

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.