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). The argument should always be a plain JavaScript Object as other types of object (DOM elements, primitive strings/numbers, host objects) may not give consistent results across browsers. To determine if an object is a plain JavaScript object, use $.isPlainObject()

Example:

Check an object to see if it's empty.

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

Support and Contributions

Need help with jQuery.isEmptyObject() or have a question about it? Visit the jQuery Forum or the #jquery channel on irc.freenode.net.

Think you've discovered a jQuery bug related to jQuery.isEmptyObject()? Report it to the jQuery core team.

Found a problem with this documentation? Report it to the jQuery API team.

* All fields are required
  • Murilo Feres

    This function does the same thing?

    function isempty(object){
    return (object.length > 0 ? true : false);
    }

  • http://www.learningjquery.com/ Karl Swedberg

    No. That would work on arrays, but objects don’t have a length property (by default).

  • 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.

  • Saintstarrow

    I think to take hasOwnProperty into account, at least enable it with an argument, would be more useful. So I could modify the prototype chain, e.g. the Object itself, and assess if an object is empty. That would be compatible with the Firefox Object toSource() method as well.

  • laktek

    Wonder why jQuery doesn't include a isBlank function?

    This function doesn't work well with blank strings.

    Anyway, Here's a function I wrote to check for blank strings – https://gist.github.com/758269…

  • laktek

    Wonder why jQuery doesn't include a isBlank function?

    This function doesn't work well with blank strings.

    Anyway, Here's a function I wrote to check for blank strings – https://gist.github.com/758269…

  • http://kflorence.myopenid.com/ Kyle Florence

    isBlank does not make sense in the context of an object or array. Yes, it would be convenient to have just one isEmpty() function, but it's very easy to check for empty strings and arrays (an empty string is falsey, as is an array with .length == 0) natively, it's not as easy to check for empty objects, hence the isEmptyObject function.