javascript - Uncaught (in promise) TypeError: filter is not a function
问题描述
我正在尝试从 API 获取数据。我将数据过滤到每个用户名中,因此我可以从每场比赛中获得杀戮、死亡和爆头。我希望输出是用户名,然后所有的杀戮,死亡,爆头相乘,但是在我可以乘以数据之前,我得到了这个错误
playerstats.js:45 Uncaught (in promise) TypeError: matchlistResponsestats.filter is not a function
at getmatchdata (playerstats.js:45)
而且我不知道出了什么问题
async function getplayerdata1() {
// Get current room
const response = await fetch(url);
const { players } = await response.json();
return Promise.all(players.map(async (player, playerIndex) => {
const { username, id } = player;
const playerid = player.id
console.log(playerid + username)
// read user matches
const response = await fetch(`https://api.site.com/user_profile/get_latest_matches?_=&id=${id}&page=1`);
const matchlist = await response.json();
return Promise.all(matchlist.map(async (match, matchIndex, array ) => {
const { id } = match;
// Read match stats
const matchlistResponse = await fetch(`https://api.site.com/match/get?_=&id=${id}`);
const matchlistResponsestats = await matchlistResponse.json();
let matchArray = matchlistResponsestats.players.length
async function getmatchdata() {
for (var i = 0; i < matchArray; i++) {
if(matchlistResponsestats.players[i].username === username) {
matchlistResponsestats.filter((item) => item.username === username).map((item) => {
return {
item: [{id: item.id, kills: item.kills, deaths: item.deaths, headshots: item.headshots}]
}
})
}
}
}
let playerstats = await getmatchdata()
console.log(playerstats)
}));
}));
}
getplayerdata1()
}
更新 console.log( MathclistResponsestats )
{id: 1862369, region_id: 0, country_id: 210, map_id: 3, flags: 0, …}
{id: 1855913, region_id: 0, country_id: 57, map_id: 5, flags: 0, …}
{id: 1856079, region_id: 0, country_id: 210, map_id: 4, flags: 0, …}
等等
解决方案
推荐阅读
- azure - 用于在 Azure 中列出非托管磁盘的 Foreach 循环
- javascript - 在搜索输入框中添加清除按钮
- python - 使用 selenium-webdriver 无法通过 xpath 找到元素
- odoo - 使用 on 函数计算两个字段
- javascript - 代码行给了我一个错误“渲染错误:”RangeError:无效的数组长度“”,但是,该行仍然按照它的意思做
- php - 如何使用 Laravel 运行 AngularJS 项目
- matlab - 如果 y 方向设置为“反向”,如何在 Matlab 中修复矢量注释头的错误对齐
- r - 如何编写一个 R 函数,从列索引而不是值中给出基因名称作为输出并发出错误?
- ruby - 无法在 Rubymine 2019.1 中使用 jRuby 9.1.17 运行规范
- python - 如何从 csv 文件中读取二维字典?