List = [1,2,3,4,5,6,7,8,9,10,11,12]
Position = [1,2]
// 方法一:使用push
for (let i=1;i<List.length;i++){
if (Position.length !==List.length){
Position.push(0)
}
}
console.log('Position:',Position); // [1,2,0,0,0,0,0,0,0,0,0,0]
// 二:使用 splice方法
for (let i=1;i<= sList.length;i++){
if (Position[i] !=List[i]){
Position.splice(i,0,0)
}
}
console.log('Position:',Position); // [1,2,0,0,0,0,0,0,0,0,0,0]
这样两个数组长度就相同了,简单吧