I am trying to update an array where an object property has a specific value.
The Details:
I have a simple method (setMissingFields(model)) that takes model as parameter. In the method I am looping over the object (model), and would like to update an array (missingArray[]) when the property is set to mandatory: true.
Below is the "clean" code I have (I have tried various nested loops using if (typeof (value) === 'object')):
model = {
name: { value: '', mandatory: false },
initials: { value: '', mandatory: false },
physicalAddress: {
addressPostalCode: { value: '', mandatory: true },
},
postalAddress: {
address1: { value: '', mandatory: true },
},
};
setMissingFields(model) {
for (const [key, value] of Object.entries(model)) {
if (value === '') {
this.missingArray.push({ FieldName: key, ExpectedValue: ''});
}
else if (typeof (value) === 'object') {
this.setMissingFields(value);
}
}
}