How to generate sequence of numbers/chars in javascript?

前端 未结 18 1205
被撕碎了的回忆
被撕碎了的回忆 2020-12-13 06:22

Is there a way to generate sequence of characters or numbers in javascript?

For example, I want to create array that contains eight 1s. I can do it with for loop, bu

18条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-13 06:35

    One liner:

    new Array(10).fill(1).map( (_, i) => i+1 )
    

    Yields:

    [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
    

提交回复
热议问题