How to write a JS loop that can achieve this?
raw data:
[
{
"firstName": "James",
"lastName": "Doe",
"emails": [
{
"emailType": "WORK",
"address": ""
},
{
"emailType": "PERSONAL",
"address": "[email protected]"
}
],
"relationship": "boyfriend",
"phones": [
{
"phoneType": "HOME",
"phoneNumber": "(514) 888-9999"
},
{
"phoneType": "CELL",
"phoneNumber": "(123) 123-4567"
},
{
"phoneType": "WORK",
"phoneNumber": "(415) 875-9999 "
}
],
"callSequence": 0
},
{
"firstName": "John",
"lastName": "Doe",
"emails": [
{
"emailType": "WORK",
"address": ""
},
{
"emailType": "PERSONAL",
"address": "[email protected]"
}
],
"relationship": "ex-husband",
"phones": [
{
"phoneType": "HOME",
"phoneNumber": ""
},
{
"phoneType": "CELL",
"phoneNumber": "(111) 111-1111"
},
{
"phoneType": "WORK",
"phoneNumber": ""
}
],
"callSequence": 0
}
]
Expected results:
[
{
"firstName": "James",
"lastName": "Doe",
"emails": [
{
"emailType": "PERSONAL",
"address": "[email protected]"
}
],
"relationship": "boyfriend",
"phones": [
{
"phoneType": "HOME",
"phoneNumber": "(514) 888-9999"
},
{
"phoneType": "CELL",
"phoneNumber": "(123) 123-4567"
},
{
"phoneType": "WORK",
"phoneNumber": "(415) 875-9999 "
}
],
"callSequence": 0
},
{
"firstName": "John",
"lastName": "Doe",
"emails": [
{
"emailType": "PERSONAL",
"address": "[email protected]"
}
],
"relationship": "ex-husband",
"phones": [
{
"phoneType": "CELL",
"phoneNumber": "(111) 111-1111"
},
],
"callSequence": 0
}
]
as you can see if the phoneNumber or mail address is empty, It should filter out and remove the complete property. As it is in a loop and there can be multiple objects, I am not sure how to write a loop to achieve this required result.
filtermight help here. Please may you share your attempt so far as a minimal reproducible example?