MarsFM
1/12/2016 - 8:39 PM

Empty object

Empty object

function isObjectEmpty(obj) {
  for(var key in obj) {
    return false;
  }
  return true;
}


// found here http://stackoverflow.com/a/2673229/64266

function isEmptyObject(obj) {
  for(var prop in obj) {
    if (Object.prototype.hasOwnProperty.call(obj, prop)) {
      return false;
    }
  }
  return true;
}

isEmptyObject({}); // true
isEmptyObject({foo:'bar'});  // false