【发布时间】:2021-03-24 17:19:06
【问题描述】:
所以我试图从 JavaScript 中的 json 文件中删除一个对象,事实证明它比以前想象的要难。
这是我的 JSON 文件的示例:
{
"tom cruise": {
"player": "tom cruise",
"team": "buf",
"position": "qb",
"overall": "82",
"OnBlock": true
},
"tim tebow": {
"player": "tim tebow",
"team": "buf",
"position": "qb",
"overall": "82",
"OnBlock": false
}
}
这是我目前所拥有的一个例子:
client.block = require ("./jsons/tradeblock.json")
if (message.content.startsWith('tb!remove')) {
player = message.content.toLowerCase().slice(10)
array = player.toLowerCase().split(" - ")
team = array[0]
position = array[1]
player = array[2]
overall = array[3]
client.block [player] = {
player: player,
team: team,
position: position,
overall: overall,
OnBlock: false
}
fs.writeFile ("./jsons/tradeblock.json", JSON.stringify (client.block, null, 4), err => {
if (err) throw err;
message.channel.send("Removing from block")
});
}
所以我想知道是否有办法检查“OnBlock”的属性是否为假,如果是的话,是否有办法从 json 中删除整个播放器。
【问题讨论】:
标签: javascript json discord.js