使用splice在当前数组特定位置插入值

在一个对象数组里面插入值

   condition: [{
        settingValue: '',
         }],
  addCondition(rowIndex) {
                this.condition.splice(rowIndex+1,0, {})
                //我这里是通过获取点击当前行的索引rowIndex来实行的
            },

重点:splice -----splice(index, num(0), item)
index------要插入的索引位置
num-------为0,如果不是0会替换当前索引处的值
item-------要插入的元素
如: a = [1,2,4]
a.splice(2,0,3) => a=[1,2,3,4]

猜你喜欢

转载自blog.csdn.net/weixin_43565820/article/details/90374686