[英]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.