I'm trying to write a function that trims all the values on each value on an object. It is working correctly however when someone adds a few spaces, it is getting saved as "", however I need it to save as "null" In the example above, I need the email field to come back as null when someone adds a input of " ", however it is coming back as ""
contact: {
firstName: "John"
lastName: "Smith"
homePhone: null
email: ""
}
Object.keys(contact).forEach(
k =>
(contact[k] =
typeof contact[k] == 'string'
? contact[k].trim()
: contact[k])
)
? (contact[k].trim() ? contact[k].trim() : null)or? (contact[k].trim() || null)