数组快速生成range的方法

//生成[item1-item9]数组
Array(9).join(0).split('').map((item,index) => 'item' + (index+1))

//生成20个对象的数组
Array.apply(null,{length:20}).map(function(item,index){
    return {name:'xxx',index:(index+1)};
});

 

for循环还是最快的,Array.join其次,Array.form方法最慢,可能以后还会有变化。

图片来源 https://jsperf.com/constarray/4

原文地址:https://www.cnblogs.com/mengff/p/7190340.html