Last active
October 22, 2022 19:35
-
-
Save oguzhancvdr/0e78e2b35d8abfddd6b428e3937ef5ea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Check Whether the Object is Empty