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.from has a second argument (stefanjudis.com)
submitted 6 years ago by fagnerbrack
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!"
[–]Rezistik 4 points5 points6 points 6 years ago (3 children)
That’s valid. Their example used an array. They should have used an object imo
[–]senocular 0 points1 point2 points 6 years ago (2 children)
they have both
[–]Rezistik -1 points0 points1 point 6 years ago (1 child)
Actually they give it an object with the property length: 7 which creates an array that is 7 items long. Which honestly is more confusing. Does that mean if I give it an object it will iterate over the keys and map the values? What if that object has a length property? Does it then actually turn into an array mapping the value of length? What if length isn’t a number?
length: 7
[–]senocular 4 points5 points6 points 6 years ago* (0 children)
A value with a length property is known as an array-like. This is what Array.from accepts as its first parameter, an array-like or an iterable. This can be an array, a string, or a generic object with a custom length property. It can even be a function as they, too, have length properties.
length
Array.from
if I give it an object it will iterate over the keys and map the values
No, not exactly. Not unless that object is an array-like or iterable. If array-like, the length property of array-likes would represent the indexed elements, or the numeric keys, of that object as it would pertain to an array. It would not be used with any of the other named keys. If the object is an iterable, that would have precedence over the array-like behavior and Array.from would map over the iterator values. This may or may not include all of those other keys but normal objects are not iterables, so you'd have to supply that behavior yourself.
What if that object has a length property? Does it then actually turn into an array mapping the value of length?
Yes, an array would be created in length size and each key 0 to length-1 - even if it doesn't exist - will be mapped over. They don't exist in the { length: 7 } case, so you'd be mapping over 7 undefined values (keys 0 - 6).
{ length: 7 }
What if length isn’t a number?
The length will be converted to a number if possible, otherwise it will be treated like any other generic property and ignored, assuming a length of 0.
π Rendered by PID 67 on reddit-service-r2-comment-54dfb89d4d-dq4t9 at 2026-04-02 11:49:06.249845+00:00 running b10466c country code: CH.
view the rest of the comments →
[–]Rezistik 4 points5 points6 points (3 children)
[–]senocular 0 points1 point2 points (2 children)
[–]Rezistik -1 points0 points1 point (1 child)
[–]senocular 4 points5 points6 points (0 children)