How To Check If An Object Has At Least One True Value
I have an array that looks like following values = {de: true, en: false, nl: false, pl: false, ru: false} I using the array to make a layout change in jsx, how can I check if the
Solution 1:
Assuming that values
is actually an object, check if .some
of the Object.values
of the object are true:
const values = {de: true, en: false, nl: false, pl: false, ru: false};
const someTruthy = Object.values(values).some(val => val === true);
console.log(someTruthy);
(if the only truthy value is true, you can use (val => val)
instead)
Post a Comment for "How To Check If An Object Has At Least One True Value"