- input ID and a recursive object to delete the item with ID
- the function I wrote is as follows
function deleteNode(paramId,obj){
console.log("enterDelete",obj)
for(let o in obj){
if(obj[o].paramId==paramId){
console.log("",obj)
obj.splice(o,1)
return obj
}
else{
if(obj[o].hasOwnProperty("subList")&&obj[o].subList.length!=0){
console.log(4,JSON.parse(JSON.stringify(obj[o].subList)))
let m=JSON.parse(JSON.stringify(obj[o].subList))
deleteNode(paramId,m)
}
}
}
}
expect
obj={
"paramId":"",
"sourcePath":"",
"subList":[
{
"paramId":500064,
"sourcePath":"Result",
"subList":[
{
"paramId":500061,
"sourcePath":"Partners",
"subList":[
]
}
]
}
]
}
paramId=500061
//
{
"paramId":"",
"sourcePath":"",
"subList":[
{
"paramId":500064,
"sourcePath":"Result",
"subList":[
//
]
}
]
}