Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to wait in js

function wait(sec) {
  const date = Date.now();
  let currentDate = null;
  do {
    currentDate = Date.now();
  } while (currentDate - date < sec*1000);
}

console.log('waiting')

wait(1)

console.log('i am done')
Comment

how to wait in javascript

function sleep(ms) {
  return new Promise(resolve => setTimeout(resolve, ms));
}
Comment

wait javascript

 wait(ms) {
        return new Promise(resolve => setTimeout(resolve, ms));
 }
Comment

js wait

function wait(milliseconds) {
  const date = Date.now();
  let currentDate = null;
  do {
    currentDate = Date.now();
  } while (currentDate - date < milliseconds);
}

function your_code() {
  //code stuff
  wait(1000); //waits 1 second before continuing
  //other code stuff
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: atob nodejs 
Javascript :: mock window jest js 
Javascript :: get last in array javascript 
Javascript :: move dom element to another parent 
Javascript :: how to get values from select multiple in js 
Javascript :: immutable array sort javascript 
Javascript :: date options js 
Javascript :: retour à la ligne react native 
Javascript :: document jquery 
Javascript :: navigate-to-an-anchor-on-another-page 
Javascript :: remove element from array in an immutable way 
Javascript :: for each js 
Javascript :: react detect screen size 
Javascript :: javascript string pop 
Javascript :: file extension regex javascript 
Javascript :: create an array of size n in javascript 
Javascript :: jquery if radio button is checked 
Javascript :: react native image source local file 
Javascript :: javascript blur focus active element 
Javascript :: js string array convert to int 
Javascript :: jest console.log 
Javascript :: how to check the last item in an array javascript 
Javascript :: clear textbox js 
Javascript :: reactjs get checkbox value 
Javascript :: click outside element jquery 
Javascript :: clear localstorage on click jquery 
Javascript :: javascript remove all event listeners 
Javascript :: install react js 
Javascript :: javascript alert get text 
Javascript :: TypeError: MiniCssExtractPlugin is not a constructor 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =