Skip to content
Advertisement

JS – fetch API, GET method return “ƒ json() { [native code] }”

I woud like to understand the difference between the two get methods, one work, the other not really but i don t understand why.

This doesn’t work:

JavaScript

and return :

ƒ json() { [native code] }

This works well:

JavaScript

and return:

{tasks: Array(4)} tasks : (4) [{…}, {…}, {…}, {…}] proto : Object

If you want to try it:

JavaScript

Advertisement

Answer

It doesn’t work because you are returning the res.json function. You have to call it and return a Promise:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement