'Why is Array.map returning different results? [duplicate]
According to my current JS understanding, All 3 lines below should return the same result, can someone please explain what I'm missing ?
1- Unexpected
[...Array(6).map((x) => 1)]
(6) [undefined, undefined, undefined, undefined, undefined, undefined]
2- expected
[...Array(6)].map((x) => 1)
(6) [1, 1, 1, 1, 1, 1]
3- unexpected
Array(6).map((x) => 1)
(6) [empty × 6]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
