2

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 array has at least one true value in JSX,

any help would be appreciated.

akano1
  • 40,596
  • 19
  • 54
  • 67

1 Answers1

9

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)

CertainPerformance
  • 356,069
  • 52
  • 309
  • 320
  • Cool shorthand with `val => val` but I would honestly stick with `val => val === true` even if the only truthy value is `true` as it's more clear to future readers (including yourself!) – Joshua Pinter Jul 11 '23 at 17:32