How to check if all values in an object are equal in TypeScript

1 Answer

0 votes
function allValuesAreEqual(obj : any) : boolean {
  	return new Set(Object.values(obj)).size === 1;
}

console.log(allValuesAreEqual({ida: 3, idb: 3, idc: 3, idd: 3}));
console.log(allValuesAreEqual({ida: 3, idb: 1, idc: 3, idd: 3}));

  
  
  
  
/*
run:
  
true
false
  
*/

 



answered Apr 13, 2022 by avibootz

Related questions

...