I need your help. With the help of fetch, I get the data and immediately draw them. On the button I want this data to be sorted, however I receive an error. What am I doing wrong?
<button id="sort_by_name">Sort</button>
JavaScript
fetch(`https://api.sampleapis.com/wines/reds`)
.then(response => response.json())
.then(data => {
for (let i = 0; i <= 25; i++) {
let vino = data[i]
let a = document.getElementById('sort_by_name');
a.addEventListener('click', () => {
data.sort((a,b) => a.wine - b.wine)
})
document.write(`<div>${vino.wine}</div>`)
}
})