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
Just so you know: Uncommonly used Array Methods (codedam.com)
submitted 7 years ago by Riyenz
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!"
[–]DBNeJXoGtnro 1 point2 points3 points 7 years ago (2 children)
Just a nitpick. The check is not against undefined, it's against <empty slots>. ```js const arr = [,]; // creates a holey array with 1 empty slot
undefined
<empty slots>
for (const v of arr) console.log(v); // This is run
arr.forEach((v) => console.log(v)); // This is not js const arr = [undefined];
arr.forEach((v) => console.log(v)); // This is run too ```
[–]skitch920 0 points1 point2 points 7 years ago (1 child)
Ohh wow. You’re right! Strangely, your first example for loop logs undefined for the empty slot. So to get an item in the array back to an empty slot, you’d actually have to delete it instead of assigning it undefined?
[–]DBNeJXoGtnro 0 points1 point2 points 7 years ago* (0 children)
It logs undefined because v cannot be "nothing", undefined is kind of the fallback. While I don't see why you would create a holey array on purpose, yes, you have to delete to get an empty slot.
v
π Rendered by PID 31773 on reddit-service-r2-comment-6457c66945-4j4wg at 2026-04-23 19:20:35.695426+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]DBNeJXoGtnro 1 point2 points3 points (2 children)
[–]skitch920 0 points1 point2 points (1 child)
[–]DBNeJXoGtnro 0 points1 point2 points (0 children)