I have a JSON object as follows
var allUsers = {
"student_a":{
id:1,
full_name:"ABC",
address:"xyz",
image:"image url"
},
"student_b":{
id:2,
full_name:"DEF",
address:"",
image:"image url"
},
"student_c":{
id:3,
full_name:"",
address:"",
image:""
}
}
In the above JSON I need to figure out how many empty fields are there in each student.
I am using the following code
_submitInfo(allUsers) {
var empty_fields = Object.entries(allUsers).map(([key, value]) => {
return this._validateStudent(value)
})
alert(JSON.stringify(empty_fields))
}
_validateStudent(studentInfo) {
empty = 0;
Object.entries(studentInfo).map(([key, value]) => {
if (value == "") {
empty++
}
})
return empty
}
But the output I get is [0,0,0] the desired output is [0,1,3].
I think promises will solve the issue but I am unaware of how will I use them in this nested case.
[0, 1, 3]check again