Trying to find a short, concise and an efficient way of checking nulls or empty values in an object coming from a user.
The naive way is to have several if and else, the other way I'm attempting is passing keys but then I can't check for nested objects.
naive way
var data = {};
if(data != null && data.username != null && data.first != null && data.last != null && data.department != null) {
}
using for loop
var data = {};
["first", "last", "email", "dept"].map(function (key) {
if(data[key] == null || data[key] == "")
console.log("reject");
});
What about nested objects?
var data = {};
["dept", "dept.id", "dept.name"].map(function (key) {
if(data[key] == null || data[key] == "")
console.log("reject");
});