cannot read property 'forEach' of undefined
程序员文章站
2022-03-04 11:03:14
...
遍历数组报错:cannot read property ‘forEach’ of undefined
在遍历之前,判断数组是否存在
$scope.list=[];
//遍历之前,判断数组是否存在
if(!$scope.list){
return;
}
$scope.list.forEach(function(item,i){
console.log(item);
})
推荐阅读
-
Vue报错:Uncaught TypeError: Cannot assign to read only property’exports‘ of object
-
npm ERR! Cannot read property 'path' of null
-
js报错 Cannot read property 'getAttribute' of null
-
微信小程序报Cannot read property 'setData' of undefined的错误
-
webpack报错Cannot read property 'presetToOptions' of undefined
-
Extjs4---Uncaught TypeError: Cannot read property ‘items’ of undefined
-
JavaScript Uncaught TypeError: Cannot read property 'value' of null
-
Cannot read property 'tap' of undefined
-
Vue报错:Uncaught TypeError: Cannot assign to read only property’exports‘ of object’#
-
el-tooltip组件中content使用Vue-i18n报错TypeError: Cannot read property ‘$t‘ of null