Returning An Object Only If All Of Its Values Are Non-null
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
Solution 1:
Just check that .every
of the values are truthy:
const returnsExampleObj = () => {
return Object.values(ExampleObj).every(Boolean) ? ExampleObj : undefined;
};
Post a Comment for "Returning An Object Only If All Of Its Values Are Non-null"