Object.prototype.isEmpty = function() { for(var key in this) { if(this.hasOwnProperty(key)) return false; } return true; } let obj = {}; if(obj.isEmpty()) { // This code will be executed if object is empty } else { // This code will be executed if object is not empty }