Return to Snippet

Revision: 63853
at June 13, 2013 02:24 by satie83

Initial Code
// Speed up calls to hasOwnProperty
var hasOwnProperty = Object.prototype.hasOwnProperty;

function is_empty(obj) {

    // null and undefined are empty
    if (obj == null) return true;
    // Assume if it has a length property with a non-zero value
    // that that property is correct.
    if (obj.length && obj.length > 0)    return false;
    if (obj.length === 0)  return true;

    for (var key in obj) {
        if (, key))    return false;

    return true;

Initial URL

Initial Description
Assuming that by empty means "has no properties of its own"

Initial Title
Javascript - How to know if an object is Empty

Initial Tags

Initial Language