So I have an object inside a json file like this:
{
"0": {
"damage_type": "Scratch",
"regions": []
},
"1": {
"damage_type": "Dent",
"regions": []
},
"2": {
"damage_type": "Dent",
"regions": [
"front side",
"front window"
]
}
}
What I am trying to accomplish is to remove the object that have empty regions. Like this:
{
"2": {
"damage_type": "Dent",
"regions": [
"front side",
"front window"
]
}
}
I am using a for loop and still unsuccessful:
jsonfile.readFile(theJsonFile, function (err, obj) {
if (err) console.error(err)
for (var i = 0; i <= Object.keys(obj).length - 1; i++) {
if (obj[i].damage_type.length < 1) {
delete obj[i]
}
}
}
Any ideas?
damage_type, notregions.