[英]array.push is not a function?
let guildMembers = [];
response.guild.members.forEach(async m => {
let userResponse;
try {
userResponse = await axios.get(`https://api.hypixel.net/player?key=KEY&uuid=${m.uuid}`);
} catch (err) {
console.error(err);
}
userResponse = userResponse.data;
if(userResponse.success != true) return res.send('Error with API.');
userResponse = userResponse.player;
var guildRank = m.rank;
guildRank = guildRank.toLowerCase();
guildRank = guildRank.charAt(0).toUpperCase() + guildRank.slice(1);
guildMembers.push(`${userResponse.displayname} | ${guildRank}`);
});
Why does this return UnhandledPromiseRejectionWarning: TypeError: guildMembers.push is not a function
?为什么这会返回
UnhandledPromiseRejectionWarning: TypeError: guildMembers.push is not a function
?
I tried doing console.log(`${userResponse.displayname} | ${guildRank}`);
我试着做
console.log(`${userResponse.displayname} | ${guildRank}`);
right before guildMembers.push(`${userResponse.displayname} | ${guildRank}`);
就在
guildMembers.push(`${userResponse.displayname} | ${guildRank}`);
and it logged what is supposed to be added correctly.它记录了应该正确添加的内容。
Try to use the for..of loop
or the traditionally for loop.尝试使用
for..of loop
或传统的 for 循环。 ForEach seems to be read only
. ForEach 似乎是
read only
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.