踩坑记录 Posted on 2023-01-06 Edited on 2023-07-12 In 经验 , 踩坑记录 在遍历数组的时候操作数组从 arr 数组中删去上去下标在 ast 数组中的元素示例:输入:arr = [1, 2, 3, 4]ast = [2,3]输出:arr 变为 [1, 2] 错误示例:hello 12345678// arr表示待操作的数组// ast中存储待删除元素的下标arr=[1,2,3,4]ast=[2,3]ast.forEach((item)=>{ arr.splice(item,1) })// arr 变成了 [1, 2, 4] 正确示例 1234arr = [1, 2, 3, 4]ast = [2, 3]arr = arr.fliter((e,index)=>!ast.includes(index))// arr 变成了 [1, 2]