I have an object :
contact:{
email: ""
firstName: ""
id: 800
lastName: ""
phone: ""
title: "MS"
url: "/api/contacts/800"
}
I would like to pass the whole object Contact to null, if the "lastName", "firstName", "Phone" and "email" fields are empty.
Do you have a solution ?
I don't know if it is what you are expecting but you can try this :
let contact = {
email: "",
firstName: "",
id: 800,
lastName: "",
phone: "",
title: "MS",
url: "/api/contacts/800"
};
if (
contact.email === "" ||
contact.firstName === "" ||
contact.lastName === "" ||
contact.phone === ""
) {
contact = null;
}
console.log(contact);