I have a json file and i fetched the data. However I cannot display it on the screen. How can I display ? I get the data results in the console however I cannot reach the parametres like product name, price.
My code is below
index.html
<body>
<div id="products"></div>
<script src="/index.js"></script>
</body>
index.js
fetch("./data.json")
.then(response => {
return response.json();
})
.then(data => console.log(data));
showProducts = products => {
const showProductsDiv = document.querySelector("#products");
products.map(product => {
const productElement = document.createElement("p");
productElement.innerText = `product Name: ${product.name}`;
showProductsDiv.append(productElement);
});
}
I also share console results




.then(showProducts)instead of sending it ONLY to the console?showProductsfunction is all set to create a<div>from the JSON results, but you aren't passing the JSON results to that function. Instead, you're just dumping them to the console and you're done. So, instead of dumping to the console, pass the results to that function . That's what my comment said.<div>Printing to the console is a debug technique. Once you've seen it work, you don't need to see it any more.