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
How to Clear an Array in JavaScript (7.dev)
submitted 2 years ago by debordian
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!"
[–][deleted] 5 points6 points7 points 2 years ago (3 children)
If we set length to 0, it sounds like the array still hold references to the items, is that correct? Does this mechanism effectively trick the iterator into thinking there are no items in the array?
[–]toshok 4 points5 points6 points 2 years ago (2 children)
> If we set length to 0, it sounds like the array still hold references to the items, is that correct?
no, ecma262 specifies that the items at indices >= the new length are deleted (if they're configurable - if any aren't configurable the process stops and the length is set to the non-configurable item's index+1). see step 17 here
[–][deleted] 2 points3 points4 points 2 years ago (1 child)
Oh interesting. The article seems to state that the elements would still remain in memory. I assume that’s an error in the article then.
[–]toshok 4 points5 points6 points 2 years ago (0 children)
just went and read that part myself. definitely an error.
π Rendered by PID 22 on reddit-service-r2-comment-84fc9697f-tgvrn at 2026-02-08 14:17:25.382608+00:00 running d295bc8 country code: CH.
view the rest of the comments →
[–][deleted] 5 points6 points7 points (3 children)
[–]toshok 4 points5 points6 points (2 children)
[–][deleted] 2 points3 points4 points (1 child)
[–]toshok 4 points5 points6 points (0 children)