Categories
TypeScript Answers

How to check if specific object is empty in TypeScript?

Spread the love

Sometimes, we want to check if specific object is empty in TypeScript.

In this article, we’ll look at how to check if specific object is empty in TypeScript.

How to check if specific object is empty in TypeScript?

To check if specific object is empty in TypeScript, we can use the Object.keys method.

For instance, we write

const isEmpty = Object.keys(obj).length === 0;

to use Object.keys to return an array of non-inherited keys in obj.

Then we get the length of that and check if it’s 0 to see if obj is empty or not.

Conclusion

To check if specific object is empty in TypeScript, we can use the Object.keys method.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.