0

I'm having trouble returning an object from a fetch request.

When I log this to console, it says the promise is pending but [[PromiseResult]] in Dev Tools shows the object correctly.

What would be the most effective way to return this?

async function() {

    const response = await fetch(`url`);

    const jsonResponse = await response.json();
    if (!jsonResponse) {
        return [];
    }
    return jsonResponse; 
} 
BWorlidge
  • 1
  • 3
  • Well… are you `await`ing *this* function when calling it? – deceze Oct 27 '20 at 14:50
  • Yes, even if I await the function call it still responds the same. – BWorlidge Oct 27 '20 at 15:22
  • You are awaiting *this* function (it doesn't have a name, so I don't know how I should refer to it…)?! `const obj = await function()` (where `function` is this `async function` from your question)? – deceze Oct 27 '20 at 15:24

0 Answers0