Currently using NodeJs
along with Express
for building a REST API. The functionality is all set up and running smoothly, but I'm facing an issue in comprehending how to iterate through the request.body
object and validate its fields for any undefined
or empty
values. My goal is to construct a new object containing only the valid data.
The structure of request.body appears as follows:
{
key: 'value',
otherKey: 'otherValue',
oneMoreKey: '',
oneMoreKey2: undefined,
oneMoreKey3: null
}
Ultimately, the desired format of my object should be:
let contactData = Object.assign({},{
'key': 'value',
'otherKey': 'otherValue'
})
I would greatly appreciate any advice or assistance on this matter.