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

后端 未结 8 1962
忘了有多久
忘了有多久 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 10:58

    Also possible solution without Array.prototype.fill:

    [...Array(10)].map((_, idx) => idx); // [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    

提交回复
热议问题