How to check if all values in an object are true or truthy with JavaScript

1 Answer

0 votes
const obj1 = {
  a: true,
  b: true,
  c: true,
};
let result = Object.values(obj1).every(value => value === true);
console.log(result);
console.log(Object.values(obj1).every(Boolean)) // truthy values

const obj2 = {
  a: 'javascript',
  b: true,
  c: 7,
};
result = Object.values(obj2).every(value => value === true);
console.log(result);
console.log(Object.values(obj2).every(Boolean)) // truthy values

  
  
  
  
/*
run:
  
true
true
false
true
  
*/

 



answered Apr 13, 2022 by avibootz
...