Object.keys() Object.hasOwnProperty(): Looping through the object
1 Object.keys() Method
The first method is the Object.keys() Method. Let’s first learn the syntax of this.
Syntax: Object.Keys(object). The parameter which this method takes is an object itself, which means the object of which own properties are to be returned. We are using Length property to check if the object has keys in it. The output is directed to the console.
Note: this method does not support older browsers.
See a Boolean value "TRUE" represents that object is empty.
2 Object.hasOwnProperty() Method: Looping through the object
The second solution is using Object.hasownproperty().
Syntax: Object.hasOwnProperty(prop). Here the parameter passed is a prop which is the name of the property to test.
See a Boolean value "FALSE" represents that object is not empty.
I hope you have understood both the methods to check if the string is empty.
Please leave a comment if you find this blog useful . Do subscribe to our website for more solutions.