plainobject

Benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
string
var isPlainObject = function(obj) {
  return typeof obj == 'object' && obj != obj.window && !obj.nodeType && JSON.stringify(obj) === "{}";
};
isPlainObject({});
isPlainObject({
  a: 1,
  b: [1, 2],
  c: 2,
  d: 0999,
  k: 19,
  l: "adfsd"
});
ready
for
var isPlainObject = function(obj) {
  if (!obj || typeof obj !== 'object' || obj.nodeType || obj.window == obj) {
    return false;
  }

  var key, objConstructor;

  try {
    // Not own constructor property must be Object
    if ((objConstructor = obj.constructor) && !hasOwnProperty(obj, 'constructor') && !hasOwnProperty(objConstructor.prototype, 'isPrototypeOf')) {
      return false;
    }
  } catch (e) {
    // IE8,9 Will throw exceptions on certain host objects
    return false;
  }

  // Own properties are enumerated firstly, so to speed up,
  // if last one is own, then all properties are own.
  /*jshint noempty:false*/
  for (key in obj) {}

  return ((key === undefined) || hasOwnProperty(obj, key));
}
isPlainObject({});
isPlainObject({
  a: 1,
  b: [1, 2],
  c: 2,
  d: 0999,
  k: 19,
  l: "adfsd"
});
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.