forEach时候删除数组某一属性项,使用splice容易出现问题
第一次forEach循环,index是0,item是1 ,arr是[1,1,2], if条件成立,使用splice最终的arr是【1,2】
第二次循环,index是1,item是2,arr是[1,2], if条件不成立,使用splice无法删除了第二个重复的1;
原因是使用splice容易使数组的index乱序。。。

正确做法:
forEach时候删除数组某一属性项,使用splice容易出现问题

应用到对象上:
forEach时候删除数组某一属性项,使用splice容易出现问题

相关文章:

  • 2022-12-23
  • 1970-01-01
  • 2022-12-23
  • 2021-12-05
  • 2021-12-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-24
  • 2021-09-05
  • 2021-08-09
  • 2022-02-01
  • 2022-02-06
相关资源
相似解决方案