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.