js解决splice删除数组某一项,索引错乱问题

问题:在for循环中,对数组进行操作,删除数组某一项使用splice,因索引错乱导致删除有漏
解决:使用倒序,从索引最后一项开始遍历

for (let len = this.correctJson.length, i = len - 1; i >= 0; i--) {
    if (this.correctJson[i].paperId == data.paperId) {
        this.correctJson.splice(i, 1);
      }
    }

猜你喜欢

转载自blog.csdn.net/qq_43246012/article/details/84376520