问题:在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);
}
}
问题:在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);
}
}