I want something like this in javascript.
for (i = 0; i < 10; i++) {
alert(i);
// now sleep 1 sec
sleep(1000);
}
is there a built in Javascript or Jquery for this?
Thank you!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There’s no such thing, directly. You would have to tell javascript to wake ‘something’ up after some time using
setTimeout.This ‘something’ would be the code that you plan to execute after the sleep, of course.
From an example I found on the internet:
But that’s fragile design. You better rethink your business logic to really do something after a second: call a different function instead of using these contrived helper variables.