Skip to content

Instantly share code, notes, and snippets.

@oguzhancvdr
Last active October 22, 2022 19:35
Show Gist options
  • Save oguzhancvdr/0e78e2b35d8abfddd6b428e3937ef5ea to your computer and use it in GitHub Desktop.
Save oguzhancvdr/0e78e2b35d8abfddd6b428e3937ef5ea to your computer and use it in GitHub Desktop.
// The below source code performs 20 times faster than the one line version
const isObjectEmpty = (object) => {
if (object.constructor !== Object) return false;
// Iterates over the keys of an object, if
// any exist, return false.
for (_ in object) return false;
return true;
};
// one line version
const isEmpty = obj => Reflect.ownKeys(obj).length === 0 && obj.constructor === Object;
@oguzhancvdr
Copy link
Author

Check Whether the Object is Empty

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment