How to check if an object is empty in TypeScript

2 Answers

0 votes
const theobj = {};
 
const objectEmpty = Object.keys(theobj).length === 0;
 
console.log(objectEmpty);
   
    

    
/*
run:
          
true 
        
*/

 



answered Jul 10, 2022 by avibootz
0 votes
const theobj = {};
 
const objectEmpty = Object.entries(theobj).length === 0 && theobj.constructor === Object;

console.log(objectEmpty);
  
   
   
/*
run:
         
true 
       
*/

 



answered Jul 10, 2022 by avibootz

Related questions

1 answer 135 views
2 answers 234 views
1 answer 93 views
1 answer 121 views
1 answer 127 views
...