不指定具体内容,只是开具体大小空间的数组,如100
1. 使用Array构造函数
const arr1 = new Array(100);
2. 使用Array.of
const arr2 = Array.of(...Array(100));
3. 使用Array.from
const arr3 = Array.from({length:100});
4. 使用fill方法
const arr4 = new Array(100).fill(undefined);
指定数组内容为下标
1. for循环
const arr1 = []'
for(let i = 0; i < 100; i++){
arr1[i] = i;}
2. Array.from
const arr2 = Array.from({length:100}, (_,index)=>index))
const arr = Array.from({ length: 30 }, (_, index) => ({ id: index, content: `data-----${index}` }))
<--设多一个id为 v-for-->
3. fill + map
const arr3 = Array(100).fill(0).map((_, index)=>index);
4. 若数组内容要是下标,就可以使用keys()
const arr4 = [...Array(100).keys()];