Array.map doesn't seem to work on uninitialized arrays

后端 未结 8 1945
忘了有多久
忘了有多久 2020-12-03 10:35

I\'m trying to set default values on an uninitialized array using the map function but it doesn\'t seem to work, any ideas on how to set default values?

Consider thi

8条回答
  •  眼角桃花
    2020-12-03 11:02

    I'd just like to point out that you can now do:

    Array(2).fill().map(_ => 4);
    

    This will return [4, 4].

提交回复
热议问题