Categories
JavaScript Answers

How to check if a JSON is empty in Node.js and JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *