For loop with fetch returning empty array

I’m writing a server route that makes api calls.

I need to make two different fetch requests cause I need more info that’s coming in the first fetch.

The problem is that I’m declaring a variable out of the promise scope and for some reason, my res.send is not awaiting until the array gets full.

I need to iterate until result 9 (I can’t use theDogApi’s predefined filters to show nine results!)

if ( {
    var myRes = [];
        .then(r => r.json())
        .then( data => {

            for (let i = 0; i < 8 && i < data.length; i++) {
                    .then(r => r.json())
                    .then(datos => {

                        myRes.push({[i], ...datos });

I’ll appreciate the help!

24 thoughts on “For loop with fetch returning empty array”

  1. 312090 545061An attention-grabbing dialogue is value comment. I believe that you need to write much more on this matter, it wont be a taboo subject nevertheless generally individuals are not sufficient to speak on such topics. To the next. Cheers 859143