0

This is currently what my console.log looks like. I only want the "trails" information to show.

How can word this so that I am able to print just the trails information?

async function apiGetAll () {
  try {
     var resp = await fetch(URL)
     var data = await resp.json();
     return data;
  }
  catch (error){
      console.log(error);
  }
}

console.log(apiGetAll());
  • 2
    all async functions return promises. you have to deal with the resulting promise outside of the call. `apiGetAll().then(data => console.log(data))` – rlemon Sep 25 '19 at 20:26
  • Possible duplicate of [How do I return the response from an asynchronous call?](https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – rlemon Sep 25 '19 at 20:27
  • Much like `fetch` and `resp.json()` must be awaited, so must `apiGetAll()`. You can do this as rlemon suggests, by chaining a `.then()` to it, or you can continue to use `await`. Note that with `await`, the line must be wrapped in an `async` function. – Tyler Roper Sep 25 '19 at 20:35

0 Answers0