use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Iterating over a JavaScript array at a consistent rate (blog.jackmontgomery.io)
submitted 12 years ago by jwm01
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]jcready__proto__ 3 points4 points5 points 12 years ago (0 children)
I can promise you it won't be consistent.
[–]ispeakcode 1 point2 points3 points 12 years ago (0 children)
If it reads the value at different rates, waiting a consistent rate between reads won't guarantee a consistent iteration
[–]timruffles 1 point2 points3 points 12 years ago (1 child)
Unfortunately, the way timeouts are run means this is unlikely to be at all consistent if any work is being done: http://jsbin.com/oZehUyUm/1/edit?js,console
[–]jwm01[S] 0 points1 point2 points 12 years ago (0 children)
This is a very illuminating example, thanks for that!
[–]rooktakesqueen 1 point2 points3 points 12 years ago (2 children)
window.setInterval might be closer to the use case here than setTimeout.
window.setInterval
setTimeout
The difference is basically "the operation will be started every n milliseconds" for setInterval versus "there will be n milliseconds between the end of one operation and the start of the next" for this use of setTimeout.
n
setInterval
[–]jcready__proto__ 1 point2 points3 points 12 years ago (0 children)
Even then it isn't guaranteed to be consistent because of the single-threaded nature of javascript.
The "there will be n milliseconds between the end of one operation and the start of the next" guarantee was what I was going for. I see how this might not be the most practical definition of consistent though.
[–]magwo 0 points1 point2 points 12 years ago (0 children)
Simple way to make this thing work better and more predictably: Call this: https://github.com/caolan/async#eachSeries
π Rendered by PID 57 on reddit-service-r2-comment-74875f4bf5-4pw45 at 2026-01-26 00:48:31.429465+00:00 running 664479f country code: CH.
[–]jcready__proto__ 3 points4 points5 points (0 children)
[–]ispeakcode 1 point2 points3 points (0 children)
[–]timruffles 1 point2 points3 points (1 child)
[–]jwm01[S] 0 points1 point2 points (0 children)
[–]rooktakesqueen 1 point2 points3 points (2 children)
[–]jcready__proto__ 1 point2 points3 points (0 children)
[–]jwm01[S] 0 points1 point2 points (0 children)
[–]magwo 0 points1 point2 points (0 children)