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

1 Answer

0 votes
const obj1 = {
  a: true,
  b: true,
  c: true,
  d: 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: 'typescript',
  b: true,
  c: 8,
};
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

Related questions

...