简体   繁体   English

TypeError:无法读取未定义的属性(读取“名称”);

[英]TypeError: Cannot read properties of undefined (reading 'name');

Error:错误:

Cannot read properties of undefined (reading 'name')无法读取未定义的属性(读取“名称”)

Code:代码:

function loop(){
    request.get({
        url: 'https://games.roblox.com/v1/games?universeIds=3652651589',
        rejectUnauthorized: false,
        headers: {
          'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3750.0 Iron Safari/537.36'
        }
      }, (err, res, body) => {
        console.log(body.data.name)
      });

    setTimeout(loop, 5000);
}

loop();

What must I do?我必须做什么?

data is an array , you can not do things like that data.name data是一个数组,你不能做类似data.name的事情
You need to use some array methods to access the information in the data or simply to specify exact index in the array in this case is 0 because the data array has only one item in it, but this is kind of not scalable...您需要使用一些数组方法来访问data中的信息,或者只是指定数组中的确切索引在这种情况下为0 ,因为data数组中只有一个项目,但这有点不可扩展......

body.data.map((currentElement) => { console.log(currentElement.name) }
and "On Development" should be printed.和“关于发展”应该被打印出来。

body.data.name替换res.data.name

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 × 类型错误:无法读取未定义的属性(读取“名称”) - × TypeError: Cannot read properties of undefined (reading 'name') TypeError:无法读取未定义的属性(读取“名称”) - TypeError: Cannot read properties of undefined (reading 'name') “TypeError:无法读取未定义的属性(读取'名称')” - "TypeError: Cannot read properties of undefined (reading 'name')" REACT JS - TypeError:无法读取未定义的属性(读取“名称”) - REACT JS - TypeError: Cannot read properties of undefined (reading 'name') TypeError:无法读取 js 中未定义(读取“名称”)的属性 - TypeError: Cannot read properties of undefined (reading 'name') in js Json TypeError:无法读取未定义的属性(读取“名称”) - Json TypeError: Cannot read properties of undefined (reading 'name') React TypeError:无法读取未定义的属性(读取“名称”) - React TypeError: Cannot read properties of undefined (reading 'name') 未捕获的类型错误:无法读取未定义的属性(读取“名称”)-ReactJS - Uncaught TypeError: Cannot read properties of undefined (reading 'name') - ReactJS 未捕获的类型错误:无法读取未定义的属性(读取“名称”)| 材质界面 - Uncaught TypeError: Cannot read properties of undefined (reading 'name') | Material UI 类型错误:无法读取未定义的属性(读取“createdTimestamp”) - TypeError: Cannot read properties of undefined (reading 'createdTimestamp')
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM