I was wondering if there is a one liner is possible for something like
let updatedUser;
if (firstName) {
updatedUser = { ...userData, firstName };
}
if (lastName) {
updatedUser = { ...userData, lastName };
}
if (password) {
updatedUser = { ...userData, password };
}
I'm just checking for empty firstName, lastName and so forth. What if I have several fields like this?
So I don't want to update any of my fields with empty values if I write
updatedUser = { ...userData, firstName, lastName, password };
Any possible alternative that exists that can tell object spread or anything else to not update if my field is empty?