settimeout inside loop
var array = [1, 2, 3, 4, 5]for(var i = 0; i < array.length; i++) { setTimeout(() => { console.log(array[i]) }, 1000);} // i = 5//you can leave the sleep constant
const sleep = (milliseconds) => {
return new Promise(resolve => setTimeout(resolve, milliseconds))
}
const doSomething = async () => {
for (/*for loop statements here*/) {
//code before sleep goes here, just change the time below in milliseconds
await sleep(1000)
//code after sleep goes here
}
}
doSomething();
Also in JavaScript:
- cache buster in angular application
- konva line thickness
- create eventlistener to close webpage js
- Javascript call() apply() bind()
- convert jquery to string
- pip install json
- install node modules in an existing project
- create server and connect to db and frontend
- get contents between tags javascript
- convert to json python
- google maps infowindow on hover
- js show span for 5 seconds
- reset navigation to specific tab react-navigation
- create fooer on print page with jquery
- node js else
- if typeof equals array javascript
- how to get the class name dynamically using jquery
- swagger.json multiple file upload
- receiving big response node js
- html select specify deafult select by js variable
- map over object javascript
- Generate a random number between 50 and 100 inclusively in javascript
- javascript convert number to spreadsheet column
- javascript get browser name