這似乎是一項很容易的任務,但由于某種原因被卡住了!我嘗試了在 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元素,但在這種情況下,我似乎有一個邏輯問題,在數組的第二級之后我無法解析任何東西任何幫助表示贊賞!
迭代復雜對象,刪除不需要的元素
LEATH
2021-05-31 10:29:16