jQuery API

jQuery.isEmptyObject()

jQuery.isEmptyObject( object ) Returns: Boolean

Description: Check to see if an object is empty (contains no properties).

  • version added: 1.4jQuery.isEmptyObject( object )

    objectThe object that will be checked to see if it's empty.

As of jQuery 1.4 this method checks both properties on the object itself and properties inherited from prototypes (in that it doesn't use hasOwnProperty).

Example:

Check an object to see if it's empty.

jQuery.isEmptyObject({}) // true
jQuery.isEmptyObject({ foo: "bar" }) // false

Comments

  • Support requests, bug reports, and off-topic comments will be deleted without warning.

  • Please do post corrections or additional examples for jQuery.isEmptyObject() below. We aim to quickly move corrections into the documentation.
  • If you need help, post at the forums or in the #jquery IRC channel.
  • Report bugs on the bug tracker or the jQuery Forum.
  • Discussions about the API specifically should be addressed in the Developing jQuery Core forum.
  • mikeschwartz
    Is it possible that an argument could be added here to specify to use hasOwnProperty() ? I initially assumed that hasOwnProperty would be taken into account here.
  • Murilo Feres
    This function does the same thing?

    function isempty(object){
    return (object.length > 0 ? true : false);
    }
  • No. That would work on arrays, but objects don't have a length property (by default).