Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

js wait for time

function sleep(milliseconds) {
  const start = Date.now();
  while (Date.now() - start < milliseconds);
}

console.log("Hello");
sleep(2000);
console.log("World!");
Comment

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 :: hello world in jsp 
Javascript :: regex match to first instance 
Javascript :: dont trigger useeffect on start 
Javascript :: inner content 
Javascript :: Set Custom User Agent react 
Javascript :: vue ref add class 
Javascript :: remove space from string javascript 
Javascript :: jquery merge objects 
Javascript :: display am pm in javascript 
Javascript :: get input value in react using hooks 
Javascript :: Regex match word js 
Javascript :: javascript check if set 
Javascript :: filter falsy values 
Javascript :: hide and show modal jquery 
Javascript :: set a previous year to the current date in javascript 
Javascript :: get random numbers javascript 
Javascript :: js set url params 
Javascript :: jquery empty and append 
Javascript :: ajax authorization header token 
Javascript :: jquery remove style 
Javascript :: asp.net core 3.1 convert system.string[] to javascript 
Javascript :: vue test form input 
Javascript :: javascript remove text from string 
Javascript :: is javascript variable also an object 
Javascript :: rgb to hex js 
Javascript :: node get current url 
Javascript :: js promis with ajax 
Javascript :: how to display items quantity into select input field 
Javascript :: copy to clipboard react native 
Javascript :: javascript const require 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =