Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • Why do you use Array.from() in Array.from(Array(26))? Array(26) is guaranteed to return an array. Commented Mar 6, 2022 at 5:11
  • Do i not need that Array.from? Commented Mar 6, 2022 at 15:57
  • No, you don't need it. Array.from() is for converting something that's array-like (e.g. a NodeList) to an actual array. Commented Mar 6, 2022 at 18:57
  • Actually, Array.from is necessary because, per the docs, "[map] is invoked only for indexes of the array which have assigned values." Array(26) creates an array of length 26 containing only empty items, so Array(26).map(...) would do nothing. It's worth noting that this is very javascript-specific. In most languages, creating an array will allocate it, even if the values in the resultant array are just whatever was in already memory at those locations. Commented Mar 6, 2022 at 22:09