Sometimes, we want to check if a JSON is empty in Node.js and JavaScript.
In this article, we’ll look at how to check if a JSON is empty in Node.js and JavaScript.
How to check if a JSON is empty in Node.js and JavaScript?
To check if a JSON is empty in Node.js and JavaScript, we use the Object.keys
method.
For instance, we write
const empty = Object.keys(myObj).length === 0;
to get an array of property keys in the myObj
object with Object.keys
.
Then we check if it’s empty by checking if length
is 0.
Conclusion
To check if a JSON is empty in Node.js and JavaScript, we use the Object.keys
method.