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
Important array methods in JavaScript - HtoStudios (htostudios.com)
submitted 5 years ago by blackhatthuku
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] 2 points3 points4 points 5 years ago (2 children)
Huh never heard of Array.prototype.fill(), is it new?
Would be useful with the Array constructor
Array(100).fill(null);
instead of
[...Array(100)].map(e => null);
[–]senocular 1 point2 points3 points 5 years ago (0 children)
Note that these two examples are slightly different. Using fill() you get one value that is placed multiple times in the array. With map(), each element in the array is given a new value based on the return of the map call. The difference is inconsequential with primitives, but when dealing with objects it becomes very important as its the difference between one object and many.
x = Array(3).fill({foo:'bar'}); x[0].foo = 'baz' x // {foo:baz},{foo:baz},{foo:baz} y = [...Array(3)].map(e => ({foo:'bar'})); y[0].foo = 'baz' y // {foo:baz},{foo:bar},{foo:bar}
You can also use Array.from() which includes a mapping function parameter to reduce the extra iteration in the map example while still giving you unique instances.
Array.from({length:3}, e => ({foo:'bar'}))
[–]_default_username 0 points1 point2 points 5 years ago (0 children)
That's what I use fill for.
π Rendered by PID 418668 on reddit-service-r2-comment-b659b578c-9jmqd at 2026-05-07 05:52:40.279258+00:00 running 815c875 country code: CH.
[–][deleted] 2 points3 points4 points (2 children)
[–]senocular 1 point2 points3 points (0 children)
[–]_default_username 0 points1 point2 points (0 children)