【求助】js 遍历children时,提示出错

代码如下:

res.forEach(e=>{
    console.log(e.name)    //这个显示正常

  e.children.forEach(item=>{
      console.log(item.name)    //这个提示错误 “Uncaught (in promise) TypeError: e.children.forEach is not a function”
  })
})

e的数据如图:
图片描述


补充:

感谢回复,先用for in 处理下了,

但是还有几个疑问希望能解答下
问题1:
我打印res
console.log(typeof res)
出来的也是对象
怎么res可以forEach呢?

问题2:
原始数据php代码如下:

$routes =[
            [
                'path'=>'/', 
                'component'=>'Layout', 
                'name'=>'首页', 
                'menu'=>"true",
                'children'=> [
                    'path'=>'/Dashboard', 
                    'component'=>'/views/Dashboard', 
                    'name'=>'仪表盘', 
                    'menu'=>"true"
                ],
            ],
        ];

在vue中axios,get获取到了这个php输出的JSON
需要怎么处理,也可以把res里的每个children也能forEach呢?

阅读 5k
5 个回答

e.children是个对象,不能用forEach遍历

Object 没有 forEach 方法,可以用 for...in 或者 for...of

e.children是一个object

Object暂时不支持forEach方法,forEach属于Array的方法/。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题