Why is the code I try to run below return as [object object]?
var request = new Request('data/some.json');
fetch(request).then(function(response) {
return response.json();
}).then(function(json) {
document.getElementById("test").innerHTML = json.items;
});
document.getElementById("test").innerHTML = json.items; is the issue here.
You should do:
document.getElementById("test").innerHTML = JSON.stringify(json.items);
This is because if you try to paint a plain JavaScript object in the DOM, it'll call the object's toString function, which will result in [object object].
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With