JAVASCRIPT   53

is object empty

Guest on 1st May 2022 04:38:43 PM

  1. import hasOwnProp from './has-own-prop';
  2.  
  3. export default function isObjectEmpty(obj) {
  4.     if (Object.getOwnPropertyNames) {
  5.         return Object.getOwnPropertyNames(obj).length === 0;
  6.     } else {
  7.         var k;
  8.         for (k in obj) {
  9.             if (hasOwnProp(obj, k)) {
  10.                 return false;
  11.             }
  12.         }
  13.         return true;
  14.     }
  15. }

Raw Paste


Login or Register to edit or fork this paste. It's free.