ES6 - generate an array of numbers

前端 未结 6 783
我寻月下人不归
我寻月下人不归 2021-01-31 08:03

Having googled for it I found two solutions:

6条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-31 08:46

    All of the other answers here create a temporary intermediate array, which isn't necessary.

    Array.from({ length: 10 }, (_, i) => i)
    

    This is essentially a map function where you map from array index to whatever you'd like, for any number of elements.

提交回复
热议问题