I was trying to create an array which is [1,2,3,...,n], so I used code new Array(10).map((value,index)=>index+1)
, but I got [empty × 5]
;
Meanwhile, new Array(10).fill(1).map((value,index)=>index+1)
, why?
How did Array.prototype.map() work?
My code:
// [empty × 10]
new Array(10).map((value,index)=>index+1)
// [1,2,...,10]
new Array(10).fill(1).map((value,index)=>index+1)