Blog

  • How to check if a JavaScript object is empty

    function isObjectEmpty(object)
    {
      var isEmpty = true;
      for(keys in object)
      {
         isEmpty = false;
         break; // exiting since we found that the object is not empty
      }
      return isEmpty;
    }

    Example:

    var myObject = {}; // Object is empty
    var isEmpty  = isObjectEmpty(myObject); // will return true;
    
    // populating the object
    myObject = {"name":"John Smith","Address":"Kochi, Kerala"}; 
    
    // check if the object is empty
    isEmpty  = isObjectEmpty(myObject); // will return false;
  • Test Blog

    This is a test blog

Design a site like this with WordPress.com
Get started