One issue I've encountered involves accessing variables from a forEach loop that iterates over an array of objects, and trying to use those variables outside the loop. I attempted to declare variables and assign them values from the loop, but I found that it only returned the first value.
let bestPrice;
let injectInstruments;
allInstruments.forEach(function (instrument) {
let price = instrument.price;
let type = instrument.type;
let description = instrument.description;
let picture = instrument.picture;
injectInstruments =instrumentsContainer.innerHTML= `<div hidden
instrumentType='${type}'class="box instrument" price="${price}">
<img class="instrument-image" src="${picture}" alt="">
<h6 class="price">${price}</h6>
<p class="instrument-description">${description}</p>
</div>`
bestPrice=price
})
console.log(injectInstruments);
console.log(bestPrice);