Let's say I have an object in which the value of each field is retrieved with an individual call:
let ExampleObj = {
foo: getFoo(),
bar: getBar(),
baz: getBaz(),
...
}
I have a function that will return the object if and only if all fields evaluate as non-null:
let returnsExampleObj = () => {
// if (!!ExampleObj.foo && !!ExampleObj.bar && !!ExampleObj.baz) {
// return ExampleObj
// } else {
// return undefined
// }
}
I can obviously just manually check each field to see whether it's null or not like in the above example, but is there a more elegant way of doing this? There may be dozens of fields in this object and to check each one manually would be very tedious.