本以为下面这行代码就可以实现:
(new Array(5)).map((item, idx) => idx)
但是:
至于为什么会是这样,我没有仔细追究,如果有知道的朋友欢迎指出。
正确方法:
// 第1种方法
Array.apply(null, {length: 10}).map((item, idx) => idx)
// 第2种方法
[...new Array(10)].map((item, idx) => idx)
// 第3种方法
Array.from({ length: 10 }, (_, i) => i)
// 第4种方法
[...new Array(10).keys()]