I am currently working on fetching and displaying data from an API. The specific data I am interested in is located within the 'equipments' array. You can see an example of this array in the image linked below:
https://i.sstatic.net/QeBhc.jpg
My challenge lies in looping through the 'equipments' array for each item and properly displaying the data. I suspect that I may not be accessing it correctly or that I am missing an additional loop somewhere in my code.
Here is the code snippet that I have been working on:
// Fetch Data
function getData() {
fetch(url)
.then((res) => res.json())
.then((data) => {
let output = "";
data.groups.equipments.forEach(function(product) {
output += `
<div class="card">
<img src=${product.photos.text} alt=${product.model} />
<h3>${product.year} ${product.manufacturer} ${product.model}</h3>
<p>${product.hours} hours</p>
<a href='https://used.battlefieldequipment.ca/en/${product["group-code"]}/${product.equipments["serial-number"]}' class="btn btn-primary">View Details</a>
</div>
`;
});
dataOutput.innerHTML = output;
})
}
getData();
Does anyone have any suggestions on how I can troubleshoot and resolve this issue?