This doesn't work. b
is just full of undefined.
const a = new Array(100);
b = a.map((c, idx) => idx);
console.log(b);
If I spread a
into a new bracketed array, b
contains the indices as expected:
const a = [...new Array(100)];
b = a.map((c, idx) => idx);
console.log(b);
What's going on here? Is there some difference in the arrays created with []
and new Array()
?
As far as I know, new Array(n)
is the only easy way to create an array with a number of elements.
Cheers.