Let's say I have the following JS Object
data = {
name: "John",
dataOfBirth: "",
externalId: 2548,
email: "john@email.com",
mobile: ""
}
I will receive an object like this with many more properties that can be either String
, Integer
or undefined
. For me to update my database, I cannot override a valid information with an empty one.
I could try if (data.email === "") delete data.email
with all of them, but that seems unpractical to maintain.
Is there any way I can scan all properties without having to name every single one of them and remove all empty/undefined ones?