javascript - Create Simple Dynamic Array

前端 未结 16 2041
刺人心
刺人心 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

    A little late to this game, but there is REALLY cool stuff you can do with ES6 these days.

    You can now fill an array of dynamic length with random numbers in one line of code!

    [...Array(10).keys()].map(() => Math.floor(Math.random() * 100))
    

提交回复
热议问题