亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

迭代復雜對象,刪除不需要的元素

迭代復雜對象,刪除不需要的元素

LEATH 2021-05-31 10:29:16
這似乎是一項很容易的任務,但由于某種原因被卡住了!我嘗試了在 SE 中找到的幾種解決方案,主要是遞歸迭代數組/對象,例如 如何迭代數組并刪除 JavaScript 中的元素和循環遍歷數組并刪除項目,而不會破壞 for 循環(和許多其他)但是沒有運氣!我有這個數組{  "condition": "AND",  "rules": [    {      "id": "loc1",      "type": "string",      "input": "text",      "operator": "equal",      "value": "test0"    },    {      "id": "sessionIgnore",      "type": "string",      "input": "text",      "operator": "equal",      "value": "ignore0"    },    {      "condition": "AND",      "rules": [        {          "id": "loc1",          "type": "string",          "input": "text",          "operator": "equal",          "value": "test1"        },        {          "id": "sessionIgnore",          "type": "string",          "input": "text",          "operator": "equal",          "value": "ignore1"        },        {          "condition": "AND",          "rules": [            {              "id": "loc1",              "type": "string",              "input": "text",              "operator": "equal",              "value": "test2"            },            {              "id": "sessionIgnore",              "type": "string",              "input": "text",              "operator": "equal",              "value": "ignore2"            }          ]        }      ]    },    {      "condition": "AND",      "rules": [        {          "id": "loc1",          "type": "string",          "input": "text",          "operator": "equal",          "value": "test3"        },        {          "id": "sessionIgnore",          "type": "string",          "input": "text",          "operator": "equal",          "value": "ignore3"        }      ]    }  ],  "valid": true}在我的情況下似乎是什么問題:在這兩種情況下,我都遞歸地遍歷數組的delete x/array.slice()方法:好像引用保持為空數組元素,然后我需要調用一個清理方法,我寧愿避免這種情況我創建了一個arrayRemove()函數,從給定的數組中刪除x元素,但在這種情況下,我似乎有一個邏輯問題,在數組的第二級之后我無法解析任何東西任何幫助表示贊賞!
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 118 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號