I have a object and I want to check if myObj contains any value within any of its attribute. However this function always return true and could not figure out what wrong have I done?
function isResponsiblePersonEmpty() {
const copyResponsiblePerson ={
"resonsiblePersonOne": [
{
"uuid": "8120BC66-4BC9-4886-820E-8A9FE488F8F7",
"name": "test",
"company": "test",
"availabilityGSMR": "test",
"availabilityMobile": "test",
"availabilityLandline": "",
"availabilityPhoneInternal": "",
"availabilityPhoneFallback": ""
},
{
"uuid": "BFE3B5AA-A61D-46B7-99A6-EC4CA2CDC0BF",
"name": "test1",
"company": "",
"availabilityGSMR": "test1",
"availabilityMobile": "",
"availabilityLandline": "test1",
"availabilityPhoneInternal": "",
"availabilityPhoneFallback": ""
}
],
"resonsiblePersonTwo": [
{
"uuid": "0414F81E-7F81-468D-BF1B-B1FA8FC34563",
"name": "test3",
"company": "",
"availabilityGSMR": "",
"availabilityMobile": "",
"availabilityLandline": "",
"availabilityPhoneInternal": "",
"availabilityPhoneFallback": ""
}
],
"resonsiblePersonFour": null,
"resonsiblePersonThree": null
}
const flatResponsiblePersonObj = _.flatMapDeep(copyResponsiblePerson);
_.forEach(flatResponsiblePersonObj, (value, key)=> {
// if any boolen value set to true, therefore responsible form filed is not empty
if (value !== null) {
return false;
}
if (value.uuid) {delete value.uuid }
if( _.isObject(value)) {
if(!_.isEmpty(value)) {
return false;
}
}
});
return true;
}
// Deep copy
var isEmpty = isResponsiblePersonEmpty();
console.log(isEmpty)
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.15/lodash.min.js"></script>