Add Timeout / Sleep function inside javascript loop
问题 I'm trying to add a sleep / delay function inside a js file, This one: var webTest = function() { let regex = /^https?:\/\//; let url = $('#list_urls').val().split('\n'); var xmlhttp = [], i; var myObj2 = [], i; for(let i = 0; i < url.length; i++) { (function(i) { xmlhttp[i] = new XMLHttpRequest(); url[i] = url[i].replace(regex, ''); xmlhttp[i].open("GET", "https://website.com/API?key=<MY_API_KEY>&url="+url[i], false); xmlhttp[i].onreadystatechange = function() { if (xmlhttp[i].readyState ===