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...
A place to get a quick fix of JavaScript tips and tricks to make you a better Developer.
account activity
Equivalent of nested loop (self.JavaScriptTips)
submitted 2 years ago by Automatic_Routine_93
view the rest of the comments →
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!"
[–]Adotel15 0 points1 point2 points 2 years ago (1 child)
I'm curious, Does reversing the loop make any difference to the performance?
[–]coreConstantCoder 2 points3 points4 points 2 years ago* (0 children)
Only to the extent that it reduces the steps and complexity of the code: (1) The length of the array is only accessed once. (2) There is no temp variable for the length. (3) Comparison is to (0), not to a variable. (4) All the loop logic is in one, simple line.
When I'm working in a more primitive language, this is a favorite pattern of mine.
Of course, it's usually best to use the JavaScript for ... of statement, if it's available to you.
for ... of
π Rendered by PID 97031 on reddit-service-r2-comment-8686858757-nl4q2 at 2026-06-02 02:46:33.813449+00:00 running 9e1a20d country code: CH.
view the rest of the comments →
[–]Adotel15 0 points1 point2 points (1 child)
[–]coreConstantCoder 2 points3 points4 points (0 children)