数组快速生成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

 

posted @ 2017-07-16 13:26  全玉  阅读(1188)  评论(0编辑  收藏  举报