Closed Th0rN13 closed 4 years ago
[...Array(3)] compiles into [].concat( Array(3) ) But [...Array(3)] - create array with 3 undefined elements, then [].concat( Array(3) ) create array with empty elements (array with empty elements cannot be iterated via map, forEach, etc.)
[...Array(3)]
[].concat( Array(3) )
So [...Array(3)].map((_, i) => i) create array [0, 1, 2], but compiled [].concat( Array(3) ).map((_, i) => i) create empty array
[...Array(3)].map((_, i) => i)
[0, 1, 2]
[].concat( Array(3) ).map((_, i) => i)
Also some issue with sparse array - spread convert empty elements to undefined
Yep, duplicate of #81
[...Array(3)]
compiles into[].concat( Array(3) )
But[...Array(3)]
- create array with 3 undefined elements, then[].concat( Array(3) )
create array with empty elements (array with empty elements cannot be iterated via map, forEach, etc.)So
[...Array(3)].map((_, i) => i)
create array[0, 1, 2]
, but compiled[].concat( Array(3) ).map((_, i) => i)
create empty arrayAlso some issue with sparse array - spread convert empty elements to undefined