Actually that doesn't work and you'll get an error. Uncaught TypeError: fetch(...).json is not a function
Because fetch() return a promise, and it doesn't have a json method on it.
It should be like this.
const url = "https://jsonplaceholder.typicode.com/todos/1"
const data = await fetch(url).then((response)=>response.json())
or this
const response = await fetch(url)
const data = await response.json()
Note that calling response.json() also return a promise so you need to await it to get the result.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Good Improvement. I will update the code.
I think you can append .json() to this:
(I didn't test it but I think it should work)
Happy to help you! :D
No it cannot be done.
Actually that doesn't work and you'll get an error.
Uncaught TypeError: fetch(...).json is not a function
Because
fetch()
return a promise, and it doesn't have ajson
method on it.It should be like this.
or this
Note that calling
response.json()
also return a promise so you need toawait
it to get the result.