在我的索引檔案中,我正在使用fs訪問這個json。我試圖洗掉陣列物件中的一個專案,其中外部 index.js 檔案中的字串輸入與 "ChannelName "鍵的值相匹配。
我試著找到頻道名稱與字串輸入相匹配的專案的索引,但這并不奏效(轉換為陣列來嘗試這個)。
有人有什么想法嗎?這有可能嗎?
。{
"DiscordServerId":""。
"token":""。
"twitch_clientID":""。
"twitch_secret":""。
"cron": "*/10 * * * *",
"channelID":""。
"roleID": "everyone",
"頻道":[
{
"ChannelName": "channel1",
"DiscordServer":""。
"twitch_stream_id":"",
"discord_nessage_id":""},
{
"ChannelName": "channel2",
"DiscordServer":"",
"twitch_stream_id":"",
"discord_nessage_id":""
},
{
"ChannelName": "channel2",
"DiscordServer":"",
"twitch_stream_id":"",
"discord_nessage_id":""
}
],
"authToken":""}
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" class="snippet-box-edit snippet-box-result" frameborder="0"></iframe>
uj5u.com熱心網友回復:
你可以用一些條件來更新channels。
const searchChannelName = "channel2";
const data = {
"DiscordServerId": "",
"token": "",
"twitch_clientID": "",
"twitch_secret": "",
"cron": "*/10 * * *"。
"channelID": "",
"roleID": "人人"。
"渠道": [
{
"ChannelName": "channel1",
"DiscordServer": "",
"twitch_stream_id": "",
"discord_nessage_id": "".
},
{
"ChannelName": "channel2",
"DiscordServer": "",
"twitch_stream_id": "",
"discord_nessage_id": "".
},
{
"ChannelName": "channel2",
"DiscordServer": "",
"twitch_stream_id": "",
"discord_nessage_id": "".
}
],
"authToken": ""
}
data.channels = data.channels. filter((node => node.ChannelName !== searchChannelName) )。
console.log(data);
<iframe name="sif2" sandbox="allow-forms allow-modals allow-scripts" class="snippet-box-edit snippet-box-result" frameborder="0"></iframe>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/322427.html
標籤:
