I am trying to get data from a free APi : API URL
I then want to push the full response into a div on my page.
I can consolelog it fine, my solution is not working.
This is what i have tried.
async function fetchData() {
fetch('https://jsonplaceholder.typicode.com/posts/1/comments')
.then((response) => response.json())
.then((json) => console.log(json));
i = json;
console.log(i);
document.getElementById('matcher').innerHTML = i.toString();
}
2
Answers
As it is an array, try to render it using map.
Try:
or, if you want an output in your procedure for a while, then
Moreover, you can use innerText instead of innerHTML render a value of some property.
OR you can use JSON.stringify