javascript – when I create an array of empty items, I can't use map with it

I tried this


> Array(3)
[ <3 empty items> ]
> // and this joins up all the nothings
> Array(3).join('-')
'--'
> // but...
> Array(3).map((x) => 'a')
[ <3 empty items> ]
> // map doesn't work with the array of empty items!

and I thought I would get the same result as this

> [undefined, undefined, undefined].map((x) => 'a')
[ 'a', 'a', 'a' ]

What’s up with that?

91 thoughts on “javascript – when I create an array of empty items, I can't use map with it”

Leave a Comment