/ Published in: JavaScript

Assuming that by empty means "has no properties of its own"
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// 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 (hasOwnProperty.call(obj, key)) return false; } return true; }
URL: http://stackoverflow.com/questions/4994201/is-object-empty
Comments
