I have an object that looks like this:
const inputObject = {
"startDate": {
"$gte": "2017-03-29T00:00:00.000Z",
"$lte": "2017-08-20T00:00:00.000Z"
},
"$and": [
{ "$or": [
{"details.thing": { "$in": [ "01" ] } },
{"details.thing": { "$in": [ "01" ] } },
{"details.thing": { "$in" : [ "01" ] } },
{"details.thing": { "$in" : [ "01" ] } }
]
},
{
"$or": []
},
{
"$or": []
}
]
}
I need to develop a function that removes any empty { "$or": [] }, sub-arrays that exist. My intended output is:
const outputObject = {
"startDate": {
"$gte": "2017-03-29T00:00:00.000Z",
"$lte": "2017-08-20T00:00:00.000Z"
},
"$and": [
{ "$or": [
{"details.thing": { "$in": [ "01" ] } },
{"details.thing": { "$in": [ "01" ] } },
{"details.thing": { "$in" : [ "01" ] } },
{"details.thing": { "$in" : [ "01" ] } }
]
}
]
}
I'm able to do this for a first level array in the object, but I'm not sure how to do it for a second level one.
$or? please include the code you tried.$or