The Object.keys Method
The first method is the Object.keys(object). The required object should be passed to the Object.keys(object) then it will return the keys in the object. The length property is used to check the number of keys. If it returns 0 keys, then the object is empty.
The hasOwnProperty() Method
The second method is looping through the object using object.hasOwnProperty(key). When the object contains the "key" property using the object.hasOwnProperty() method, a function is created. This would return true if it could find no keys in the loop, which means that the object is empty. If any key is found, the loop breaks returning false. Use this method for older browsers that do not support the first method.
The JSON.stringify Method
If you JSON.stringify the object and the result is an opening and closing bracket, it means that the object is empty.
Object.keys() returns the array whose elements are strings that correspond to the enumerable properties found directly upon the object. The property order is similar to that given by the object manually in a loop applied to the properties.
Object.keys() is used to return enumerable properties of a simple array, of an array like an object, and an array like object with random ordering.