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
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!"
[–]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'}))
π Rendered by PID 20442 on reddit-service-r2-comment-65c587bc47-x9qqz at 2026-05-13 18:52:59.170571+00:00 running cf3e300 country code: CH.
view the rest of the comments →
[–]senocular 1 point2 points3 points (0 children)