-
Notifications
You must be signed in to change notification settings - Fork 191
Expand file tree
/
Copy pathValidateObjects.js
More file actions
21 lines (17 loc) · 981 Bytes
/
ValidateObjects.js
File metadata and controls
21 lines (17 loc) · 981 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
var obj = { cidade : undefined, estado : "", cep : "123" };
if (obj.cidade === undefined) console.log("cidade não tem valor");
if (obj.empresa === undefined) console.log("estado não tem valor");
if (obj.representante === undefined) console.log("cep não tem valor");
var obj = { cidade : "abc", estado : "", cep : "123" };
if (obj.cidade === undefined || obj.cidade === "" ||
obj.empresa === undefined || obj.empresa === "" ||
obj.representante === undefined || obj.representante === "") console.log("algum campo não tem valor");
var obj = { cidade : undefined, estado : "", cep : "123" };
if (temCampoInvalido(obj)) console.log("algum campo não tem valor");
var obj = { cidade : "cidade", estado : "", cep : "123" };
if (temCampoInvalido(obj)) console.log("algum campo não tem valor");
function temCampoInvalido(obj) {
for (var value of Object.values(obj)) if (value === undefined) return true;
return false;
}
//https://pt.stackoverflow.com/q/313639/101