Array · 数组补满

124 阅读1分钟

基本类型

const a = new Array(2).fill('555') //['555', '555']
const b = new Array(2).fill(true) //[true, true]

对象

如果 fill 的参数为引用类型,会导致都执行同一个引用类型,不能用fill

// restList是补满rowNum长度
  const restList: any[] = []
  for (let i = 0; i < realConfig.value.rowNum - list.value.length; i++) {
    restList.push({})
  }
  list.value.push(...restList)