I would like to know how to get the array object in nested array object using javascript.
Below is the object obj, should get the obj with the children1 status having Active and Updated.
var obj = [{
"id": 1,
"status":"updated",
"code": "product",
"children": [
{
"id" : 20,
"title": "cafe",
"children1": [
{"id": "2", "title": "SG", "status": "Active"},
{"id": "3", "title": "TH", "status": "Updated"},
{"id": "4", "title": "MY", "status": "Deleted"}
]
},
{
"id" : 21,
"title": "others",
"children1": [
{"id": "5", "title": "tours", "status": "Active"},
{"id": "6", "title": "services", "status": "Updated"},
{"id": "7", "title": "finance", "status": "Deleted"}
]
}
]
}]
function getActiveUpdtedObj (obj){
var result = obj.filter(e=>e.children.filter(i=>i.children1.status !=="Deleted"));
console.log(result);
}
this.getActiveUpdtedObj(obj);
Expected Result
[{
"id": 1,
"status":"updated",
"code": "product",
"children": [
{
"id" : 20,
"title": "cafe",
"children1": [
{"id": "2", "title": "SG", "status": "Active"},
{"id": "3", "title": "TH", "status": "Updated"}
]
},
{
"id" : 21,
"title": "others",
"children1": [
{"id": "5", "title": "tours", "status": "Active"},
{"id": "6", "title": "services", "status": "Updated"}
]
}
]
}]