I have multiple objects in array. It has values array with value property in object. when all value properties are empty. I want to remove whole object.
I tried it but i am not able to produce output. Please help me.
var data = [
{
"field": "surname",
"values": [
{
"id": "drivingLicenseFront",
"value": "",
"isAvailable": true
},
{
"id": "passport",
"value": "",
"isAvailable": true
}
],
"status": "passed"
},
{
"field": "given names",
"values": [
{
"id": "drivingLicenseFront",
"value": "",
"isAvailable": true
},
{
"id": "passport",
"value": "",
"isAvailable": true
}
],
"status": "passed"
},
{
"field": "date of birth",
"values": [
{
"id": "drivingLicenseFront",
"value": "25.07.1974",
"isAvailable": true
},
{
"id": "passport",
"value": "05 JUN /JOIN 57",
"isAvailable": true
}
],
"status": "passed"
}
];
for (let x = data.length-1; x >= 0; x--) {
let count = 1;
var dataValueLength = data[x].values.length;
for (let y = 0; y < data[x].values.length; y++) {
if (data[x].values[y].value === "") {
count++;
}
}
if (dataValueLength == count) {
data.splice(x, 1)
}
}
console.log(JSON.stringify(data));
In above scenario, output should be only one object that is "date of birth".
"values": []or where allvalues.value = ""? Or what of the two?date of birthhad a third item in values array that had avalueproperty of an empty string? Would you want thedate of birthobject have only 2 items in values or 3?