Cannot read properties of undefined (reading ‘forEach‘)

报错

 Cannot read properties of undefined (reading 'forEach')

原因

使用 forEach 的对象不是 Array 类型,建议检查下代码。

解决方法

执行程序前做校验,或者使用默认值语法。

function arr(data: any[] = []) {
    
    
  data.forEach((e) => {
    
    
    ...
  })
}

猜你喜欢

转载自blog.csdn.net/m0_53808238/article/details/129796820