1. 程式人生 > >javascript快速產生數組方法

javascript快速產生數組方法

數組 ava nbsp code java apply javascrip ply span

//生成[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)};
});

javascript快速產生數組方法