Javascript 为什么api数据没有出现?我的代码是对的还是错的?

Javascript 为什么api数据没有出现?我的代码是对的还是错的?,javascript,arrays,api,vue.js,console.log,Javascript,Arrays,Api,Vue.js,Console.log,这是来自某个网站的api数据 date: (...) dateTimeGMT: (...) matchStarted: (...) squad: (...) team-1: (...) team-2: (...) toss_winner_team: (...) type: (...) unique_id: (...) winner_team: (...) 如果我编写console.logresponse.date或console.logresponse.toss_winner_team,则代码

这是来自某个网站的api数据

date: (...)
dateTimeGMT: (...)
matchStarted: (...)
squad: (...)
team-1: (...)
team-2: (...)
toss_winner_team: (...)
type: (...)
unique_id: (...)
winner_team: (...)
如果我编写console.logresponse.date或console.logresponse.toss_winner_team,则代码工作正常,但如果我编写console.logresponse.team-1或console.logresponse.team-2,则结果是NaN

您可以在附图中看到api数据:


JavaScript正试图评估这种表达式。尝试以阵列样式访问它:

console.log(response["team-1"])
你到底想做什么?如果响应是数组,则应首先迭代响应:

response.forEach(row => console.log(row["team-1"]));

如果属性名称为team-1,则按如下方式访问它 答复[第1小组]

执行response.team-1被视为属性值的减法运算

如果property response.team中的数据是整数,则可以通过 console.logparseIntresponse.team-1


team-1不是javascript变量的合法名称,因此您需要使用带有字符串调用的数组来代替response[team-1]

response.team-2应该是什么意思?我不知道什么不适合您,因为您没有按照应该的方式粘贴代码。getData{axios.get,{params:{apikey:'GBWsx5I1qWQta3pXPjmzRpYJCzz2'}.thenresponse=>{this.Player=response.data.matches;console.logresponse.data.matches.team-1;}},谢谢你的apiKey。顺便说一句,matches是一个数组,而不是一个object.getData{axios.get,{params:{apikey:'GBWsx5I1qWQta3pXPjmzRpYJCzz2'}。thenresponse=>{this.Player=response.data.matches;console.logresponse.data.matches[team-1];},为什么要做response.data.matches[team-1]?您正在访问与response类似的toss_winner_team属性。toss_winner_team team team team team-1属性也处于相同的结构中,因此请尝试使用response。[team-1]显示您编写的代码。不然我们怎么查?
response.team-1