Categories
TypeScript Answers

How to get the object length in TypeScript?

Spread the love

Sometimes, we want to get the object length in TypeScript.

In this article, we’ll look at how to get the object length in TypeScript.

How to get the object length in TypeScript?

To get the object length in TypeScript, we can use the Object.keys method and the array length property.

For instance, we write

Object.keys(customer).length;

to return an array of non-inherited keys from the customer object with Object.keys.

Then we get the length of the array with length.

Conclusion

To get the object length in TypeScript, we can use the Object.keys method and the array length property.

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.