Object Empty Tests

Benchmark created on


Setup

const testObject = {};
for (let i = 0; i < 250; i++) {
	testObject[i] = 2;
}

Test runner

Ready to run.

Testing in
TestOps/sec
for in
function isObjectEmpty(obj) {
  for (let prop in obj) {
    if (obj.hasOwnProperty(prop)) {
      return false;
    }
  }
  return true;
}

console.log(isObjectEmpty(testObject));
ready
Object.keys()
function isObjectEmpty(obj) {
  return Object.keys(obj).length === 0;
}

console.log(isObjectEmpty(testObject));
ready

Revisions

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