I'm seeking a more efficient method to iterate through a JSON object and retrieve a specified number of objects. I am currently manually hardcoding the data retrieval using [] for key-value pairs, but I believe there must be a better approach to accomplish this.
Below is my code snippet:
fetch("https://api.coinmarketcap.com/v2/ticker/?start=0&limit=200")
.then((response) => {return response.json(); })
.then((resp => {
console.log(resp);
let price = resp.data;
showPrice(price);
}))
function showPrice(cryptoPrice) {
document.querySelector(".results").innerHTML = `
<div class="container text-center">
// Repeating structure removed for brevity
</div>
`;
}
// Styling CSS omitted for brevity
<div class="results"></div>
If you'd like to explore the complete code further, here is a link to the CodePen project: https://codepen.io/Brushel/pen/mjrqXr