javascript - Create Simple Dynamic Array

前端 未结 16 2045
刺人心
刺人心 2020-12-14 06:53

What\'s the most efficient way to create this simple array dynamically.

var arr = [ \"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\", \"10\"];
<         


        
16条回答
  •  没有蜡笔的小新
    2020-12-14 07:21

    I had a similar problem and a solution I found (forgot where I found it) is this:

    Array.from(Array(mynumber), (val, index) => index + 1)

提交回复
热议问题