Perhaps the title is a bit confusing, but I couldn't come up with a better way to phrase it.
I have a function that determines the value of each property within a contact object and returns 'No Data' if the value is null/empty/undefined. However, within each contact object, there is an 'Addresses' array containing address objects. I need to access the first/[0] index using a similar method so that manual creation of functions to search the values of each addressLine1, addressLine2 etc. property is not necessary.
In essence, I am looking to return 'No Data' for empty values of addressLine1, addressLine2, etc.
Here is an example structure of each object:
'Items': [
{
'property1': 'propertyValue',
'property2': 'propertyValue',
'property3': 'propertyValue',
'addresses': [
{
'addressLine1': 'propertyValue',
'addressLine2': 'propertyValue',
'addressLine3': 'propertyValue',
},
{
'addressLine1': 'propertyValue',
'addressLine2': 'propertyValue',
'addressLine3': 'propertyValue',
},
{
'addressLine1': 'propertyValue',
'addressLine2': 'propertyValue',
'addressLine3': 'propertyValue',
}
]
}
]
The current code I have to access top level property values looks like this:
items.forEach(function(obj) {
Object.keys(obj).forEach(function (property) {
if (obj[property] === '' || obj[property] === null || obj[property] === undefined) {
obj[property] = '*No Data*';
}
});
});