Checks whether all properties of an object have truthy values, except for keys that are listed as optional.
optionalKeys
false
The object whose values should be validated.
An array of keys that are exempt from truthy validation. Defaults to an empty array.
true if all required keys have valid (truthy or false) values, otherwise false.
true
const result = hasAllTruthyValues({ a: 1, b: "test", c: false });console.log(result); // true (all keys are valid, `false` is allowed) Copy
const result = hasAllTruthyValues({ a: 1, b: "test", c: false });console.log(result); // true (all keys are valid, `false` is allowed)
const result = hasAllTruthyValues( { a: "", b: 123, c: null }, ["a", "c"]);console.log(result); // true (`a` and `c` are optional) Copy
const result = hasAllTruthyValues( { a: "", b: 123, c: null }, ["a", "c"]);console.log(result); // true (`a` and `c` are optional)
const result = hasAllTruthyValues({ a: 0, b: undefined });console.log(result); // false (both values are falsy and not optional) Copy
const result = hasAllTruthyValues({ a: 0, b: undefined });console.log(result); // false (both values are falsy and not optional)
Checks whether all properties of an object have truthy values, except for keys that are listed as optional.
optionalKeysare always considered valid, regardless of their values.false.