So i made a async/await request and wanted to output the response in json format: I first tried to use alert to alert the response, it displayed the response in an alert box. Then i tried logging it to the console, and it did the same thing in the console. Then i tried displaying it to the webpage using the HTML DOM and interesting things happened. Instead of displaying the response to the webpage, it displayed [object Object].
Now i am curious: Can you actually display json response to the webpage?
Btw this is how my request looks like:
async function syncf() {
try {
const response = await fetch("https://reqres.in/api/users/2")
if (response.ok) {
const jsonResponse = await response.json()
document.getElementById("response").innerHTML = jsonResponse
}
} catch(error) {
console.log(error)
}
}
syncf()