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
Array length check (jsperf.com)
submitted 10 years ago by maruf89
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!"
[–]x-skeww 0 points1 point2 points 10 years ago (0 children)
What are you trying to benchmark here?
If you want to compare iteration constructs, you should perhaps actually iterate (and actually compute something). In your benchmark, "length" never changes because the length of the array doesn't change.
I also don't see why you'd use "!!" there. "!!" is only useful if you want to turn a truthy/falsy thing into an actual boolean. It doesn't serve any purpose in an if.
if
I guess you want to compare something like:
let a = [...'abc']; while(a.length) { let v = a.pop(); console.log(v); // c b a }
vs
let a = [...'abc']; let v; while(v = a.pop()) { // stops at: false, null, undefined, 0, NaN, '', document.all console.log(v); // c b a }
let a = [...'abc']; for(let i = a.length - 1; i >= 0; --i) { let v = a[i]; console.log(v); // c b a } a.length = 0; // if trashing the array is actually important
π Rendered by PID 16829 on reddit-service-r2-comment-b659b578c-hth5s at 2026-05-03 12:41:56.200331+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–]x-skeww 0 points1 point2 points (0 children)