I´m trying to loop an array of objects inside a fetch. Is there a way I can do a loop inside a fetch or make the fetch return the array somehow?
This is what I´ve attempted:
fetch(url)
.then(response => response.json())
.then(data =>
for (i = 0; i < data.length; i++) {
console.log(data[i])
})
datais an array, then your code will work (though you're missing curly brackets). If it's not, then convert it to an array.=> {for (...) {...}}awaitit (in which case you'll get whatever the lastthenhandler returns), or process and forward data to whatever function needs to work with it next by calling that function.fetch()(and athen()chain). You'll need to learn how to use promises correctly to "return an array". You can also turn yourthen-ey code intoasync/await, which is easier to understand.