类型错误:无法调用未定义的方法“forEach”

TypeError: cannot call method 'forEach' of undefined

本文关键字:方法 forEach 未定义 调用 错误 类型      更新时间:2023-09-26

当我尝试将静态目录添加到我的代码中时,出现此错误:

TypeError: cannot call method 'forEach' of undefined

谁能帮我解决这个问题?

['adobeair','applewebkit','bs3','chrome','css','font-awesome','hpwos','images','img','js', 'Opera', 'plugins'].forEach(function (dir)
{
    app.use('/template/'+dir, connect.static(__dirname+'/template/'+dir));
});

谢谢

最好的方式 -

var dirs = ['adobeair','applewebkit','bs3','chrome','css','font-awesome','hpwos','images','img','js', 'Opera', 'plugins'];
dirs.forEach(function(dir) { 
console.log('dir name : '+dir);
});

它正在工作或我:)