How do I test for an empty JavaScript object?
ECMA 5+: // because Object.keys(new Date()).length === 0; // we have to do some additional check obj // 👈 null and undefined check && Object.keys(obj).length === 0 && Object.getPrototypeOf(obj) === Object.prototype Note, though, that this creates an unnecessary array (the return value of keys). Pre-ECMA 5: function isEmpty(obj) { for(var prop in obj) { if(Object.prototype.hasOwnProperty.call(obj, … Read more