Instead of setTimeout you can run them sequentially. I assume there is a callback the request() parameter for your request() function.
function makeRequest(arr, i) { if (i < arr.length) { request(arr[i].url, function() { i++; makeRequest(arr, i); }); } } makeRequest(data, 0);
If you need a bit more time between requests, add setTimeout to the callback.
function makeRequest(arr, i) { if (i < arr.length) { request(arr[i].url, function() { i++; setTimeout(makeRequest, 1000, arr, i); }); } } makeRequest(data, 0);
source share