-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
  • 38,208
  • 18
  • 49
  • 65

1 Answers1

2

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
  • 313,535
  • 40
  • 245
  • 254