Javascript block loop logic

Asked

Viewed 46 times

-1

My code has an array with numerous objects, that abjects which are URL’S, with which I loop through this array and make a request for each url of the array. But I need my loop to go through the block array, Ex: from 10 to 10; until the end, all so that it does not do it instantly and end up overloading the server and also so that it does not take too long to go through 1 in 1 because the array is very large, at code base is basically this.

const array = ["URL-1","URL-2","URL-3"] etc...

for (var i = 0; i < array.length; i++) {
    axios.get(array[i], (res) => {
        const res = res;
    });
}

1 answer

-1

good in the end I myself ended up finding a viable way.

const main = async () => 
{
    if ( array.length >= index ) 
    {   
        if (index != count) 
        {
            console.log(index); 
            index++ 
            main();             
        }else{
            console.log("+10");
            count = (count + 10);
        }
        
    }else{
        console.log("end");
        clearInterval(handle);
    }
}
const handle = setInterval(main, 2000);

Thanks for nothing.

  • 1

    "Thank you for nothing" is offensive. No one is obliged to help you. Much less at the time you expect. If you think this site is for this, you’re in the wrong place.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.