JavaScript
and I would like to check if all values of the object keys are different from null
, undefined
, 0, "" and "".
I run each value of my object with forEach
, however I want the first condition to be executed only if all the values are different than the one I commented above.
In my code, if only one value is no longer null
, undefined
, 0, "" or "", my code executes the condition and does not enter else else.
Beautified JavaScript
:
let dados = {
nome: nome,
email: email,
telefone: telefone,
cursos: cursos,
cidade: cidade
};
let condicao = false;
Object.values(dados).forEach(function (campo) {
console.log(campo);
if (campo !== "" && campo !== null && campo !== " " && campo !== false && campo !== 0 && campo !== undefined) {
//Execute algo
} else {
if (condicao == false) {
alert("Preencha todos os campos");
condicao = true;
}
}
})
Can anyone help me?